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

%aunique fails if a disambiguation is a non-fixed field #2678

Closed
devster31 opened this issue Aug 29, 2017 · 3 comments · Fixed by #4140
Closed

%aunique fails if a disambiguation is a non-fixed field #2678

devster31 opened this issue Aug 29, 2017 · 3 comments · Fixed by #4140
Labels
bug bugs that are confirmed and actionable

Comments

@devster31
Copy link

devster31 commented Aug 29, 2017

I recently encountered this behaviour while trying out paths with %aunique{} and the below config.

paths:
    default: $albumartist/$albumartist - $album%ifdef{albumdisambig, - $albumdisambig}%aunique{albumartist album year, catalognum label} [$format]/%if{$multidisc,$disc-}$track. $title

This will produce the below output (part of).

Franz Ferdinand - Franz Ferdinand [678] [MP3]
Franz Ferdinand - Franz Ferdinand [679] [FLAC]

This means that different format, which already produce a different path, still get deduplicated by %aunique, which is intended behaviour.
I would, however, want to avoid this and @sampsyo referred to #2610, from which I slightly adapted this snippet:

album_fields:
    albumformat: |
        format_list = []
        [format_list.append(item.format) for item in items if item.format not in format_list]
        return format_list

The snippet works for the beet list command, however it does not work as a disambiguator for %aunique:

paths:
    default: $albumartist/$albumartist - $album%ifdef{albumdisambig, - $albumdisambig}%aunique{albumartist album year albumformat, catalognum label} [$format]/%if{$multidisc,$disc-}$track. $title

And produces _no such column∶ format_ in the file name.
I believe this is caused by this piece:

        for key in keys:
            value = album.get(key, '')
            subqueries.append(dbcore.MatchQuery(key, value))

found in beets/library.py.
My understanding is that the key gets queried to the database but not with the fields generated by the inline plugin. Would it be feasible to allow inline fields to be queried?

Setup

  • OS: Raspbian + Docker
  • Python version: 3.6.1
  • beets version: 1.4.5
  • Turning off plugins made problem go away (yes/no): no
@devster31 devster31 changed the title %aunique custom identifiers %aunique custom disambiguators Aug 29, 2017
@RollingStar
Copy link
Contributor

I've found responses like this _no such column∶ format_ in my own use of aunique(). Have you tried a path format like this?

%aunique{albumartist album year $albumformat, catalognum label}

Notice the $. You need $ in the first set of disambiguators for any field defined with inline. You need to not use $ in the second set of disambiguators. Example:

%aunique{albumartist album year $albumformat, cust_field catalognum label}

@devster31
Copy link
Author

This is my output after your suggestion:

$ beet ls -f '$albumartist - $album %aunique{albumartist album year $albumformat, catalognum label} [$format]' album::^Franz Ferdinand
Franz Ferdinand - Franz Ferdinand <no such column: 'MP3'> [MP3]
Franz Ferdinand - Franz Ferdinand <no such column: 'MP3'> [MP3]
Franz Ferdinand - Franz Ferdinand <no such column: 'FLAC'> [FLAC]

It could be something related to my setup though.

@sampsyo sampsyo changed the title %aunique custom disambiguators %aunique fails if a disambiguation is a non-fixed field Aug 29, 2017
@sampsyo sampsyo added the bug bugs that are confirmed and actionable label Aug 29, 2017
@sampsyo
Copy link
Member

sampsyo commented Aug 29, 2017

Thanks for the detailed report. This is in fact a bug—I don't think even a flexible attribute would work as a disambiguator as it stands. The problem is indeed with the MatchQuery construction that you pointed to. Namely, the problem is that the FieldQuery base class constructor defaults to fast=True, which only works for fixed fields:

def __init__(self, field, pattern, fast=True):

To read more about fast and slow queries, check out this blog post. We need to pass True for the fast parameter when the field name is non-fixed.

The right fix is probably a helper function that will automatically choose the fast parameter based on the kind of field being queried.

jcassette added a commit to jcassette/beets that referenced this issue Nov 11, 2021
jcassette added a commit to jcassette/beets that referenced this issue Nov 11, 2021
jcassette added a commit to jcassette/beets that referenced this issue Nov 11, 2021
sampsyo added a commit that referenced this issue Nov 11, 2021
Use slow queries for flexible attributes in aunique (fix #2678, close #3553)
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.

3 participants