Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

%ifdef does not work on flexattr fields with int or float #3852

Closed
wazabees opened this issue Feb 8, 2021 · 3 comments · Fixed by #3982
Closed

%ifdef does not work on flexattr fields with int or float #3852

wazabees opened this issue Feb 8, 2021 · 3 comments · Fixed by #3982
Labels
bug bugs that are confirmed and actionable

Comments

@wazabees
Copy link

wazabees commented Feb 8, 2021

Problem

If I try beet ls -a -f '$albumartist - (%if{$original_year,$original_year,$year}) - $album%ifdef{albumdisambig, (%title{$albumdisambig}),}%ifdef{albumrating, ($albumrating),}' year:2021 then beets will return the album rating for the albums that has the field defined. For albums without the rating, $albumrating is returned.

Example:

Artist1 - (2021) - Albumname1 (2.0)
Artist2 - (2021) - Albumname2 ($albumrating)

Further information on the forum:
https://discourse.beets.io/t/album-rating-as-a-flexible-attribute-in-5-increments/1687/3

Comment from adrian:
reading over the implementation of %ifdef, I can see now how it would be confused about types with a default value. That is, int or float fields will produce a '0' string for unset values through the formatter, which gets interpreted as non-missing. We clearly need better logic for this.

Setup

  • OS: Arch Linux
  • beets version 1.5.0
  • Python version 3.9.1
  • plugins: edit, extrafiles, fetchart, importadded, importfeeds, info, inline, lastimport, mbcollection, mbsync, mpdstats, mpdupdate, originquery, scrub, smartplaylist, types, zero
@sampsyo sampsyo added the bug bugs that are confirmed and actionable label Feb 9, 2021
@sampsyo
Copy link
Member

sampsyo commented Feb 9, 2021

Thanks! The right fix here is to change the tmpl_ifdef method to look directly for the presence of a field rather than trying to go through the formatter.

@michaeltoohig
Copy link

I'm also facing this issue and glad to know it can be fixed. I thought it was my own user error though.

@spavitra1
Copy link

Hello, I would like to work on this bug.

adsultana added a commit to adsultana/beets that referenced this issue Jun 16, 2021
sampsyo added a commit that referenced this issue Jun 17, 2021
Fix ifdef behavior with non-string fields (bug #3852)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug bugs that are confirmed and actionable
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants