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

Erroneous @classmethod on NoneQuery.match #3516

Closed
adamjakab opened this issue Mar 15, 2020 · 0 comments
Closed

Erroneous @classmethod on NoneQuery.match #3516

adamjakab opened this issue Mar 15, 2020 · 0 comments
Labels
bug

Comments

@adamjakab
Copy link
Contributor

@adamjakab adamjakab commented Mar 15, 2020

Problem

When running a query against the library that contains a NoneQuery such as:

dbcore.query.NoneQuery(u'gender', fast=False)

beet exits with the following traceback:

Traceback (most recent call last):
  File "/Users/jackisback/opt/miniconda3/envs/beetsdevel/bin/beet", line 8, in <module>
    sys.exit(main())
  File "/Users/jackisback/opt/miniconda3/envs/beetsdevel/lib/python3.7/site-packages/beets/ui/__init__.py", line 1266, in main
    _raw_main(args)
  File "/Users/jackisback/opt/miniconda3/envs/beetsdevel/lib/python3.7/site-packages/beets/ui/__init__.py", line 1253, in _raw_main
    subcommand.func(lib, suboptions, subargs)
  File "/Users/jackisback/Documents/Projects/Python/BeetsPluginXtractor/beetsplug/xtractor/command.py", line 133, in func
    self.xtract()
  File "/Users/jackisback/Documents/Projects/Python/BeetsPluginXtractor/beetsplug/xtractor/command.py", line 157, in xtract
    if len(library_items) == 0:
  File "/Users/jackisback/opt/miniconda3/envs/beetsdevel/lib/python3.7/site-packages/beets/dbcore/db.py", line 741, in __len__
    for obj in self:
  File "/Users/jackisback/opt/miniconda3/envs/beetsdevel/lib/python3.7/site-packages/beets/dbcore/db.py", line 689, in _get_objects
    if not self.query or self.query.match(obj):
  File "/Users/jackisback/opt/miniconda3/envs/beetsdevel/lib/python3.7/site-packages/beets/dbcore/query.py", line 462, in match
    return all([q.match(item) for q in self.subqueries])
  File "/Users/jackisback/opt/miniconda3/envs/beetsdevel/lib/python3.7/site-packages/beets/dbcore/query.py", line 462, in <listcomp>
    return all([q.match(item) for q in self.subqueries])
  File "/Users/jackisback/opt/miniconda3/envs/beetsdevel/lib/python3.7/site-packages/beets/dbcore/query.py", line 472, in match
    return any([q.match(item) for q in self.subqueries])
  File "/Users/jackisback/opt/miniconda3/envs/beetsdevel/lib/python3.7/site-packages/beets/dbcore/query.py", line 472, in <listcomp>
    return any([q.match(item) for q in self.subqueries])
  File "/Users/jackisback/opt/miniconda3/envs/beetsdevel/lib/python3.7/site-packages/beets/dbcore/query.py", line 168, in match
    return item[cls.field] is None
AttributeError: type object 'NoneQuery' has no attribute 'field'

The above example is using a flex attribute but the same error can be reproduced using a fixed field such as: dbcore.query.NoneQuery(u'title')

This behaviour has already been reported in #1634, identifying the problem within the @classmethod decorated match method using self in the NoneQuery class. The bug was fixed by correcting self to cls leaving the method itself decorated with @classmethod.

Setup

beets version 1.4.9
Python version 3.7.6
plugins: info, xtractor

  • Turning off plugins made problem go away (yes/no): no

Possible solution

The NotQuery.match method should probably not be decorated with @classmethod.

@sampsyo sampsyo added the bug label Mar 15, 2020
@sampsyo sampsyo closed this in 5d39d02 Mar 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.