Skip to content

Crash when sorting on a flexible attribute that is present on some items and missing on others #3461

Description

@rain0r

Use case

I'm trying to use beets to sort by item rating:

$ beet ls -f '$path' rating-
Traceback (most recent call last):
  File "/usr/lib/python-exec/python3.7/beet", line 11, in <module>
    load_entry_point('beets==1.5.0', 'console_scripts', 'beet')()
  File "/usr/lib/python3.7/site-packages/beets/ui/__init__.py", line 1267, in main
    _raw_main(args)
  File "/usr/lib/python3.7/site-packages/beets/ui/__init__.py", line 1254, in _raw_main
    subcommand.func(lib, suboptions, subargs)
  File "/usr/lib/python3.7/site-packages/beets/ui/commands.py", line 1072, in list_func
    list_items(lib, decargs(args), opts.album)
  File "/usr/lib/python3.7/site-packages/beets/ui/commands.py", line 1067, in list_items
    for item in lib.items(query):
  File "/usr/lib/python3.7/site-packages/beets/dbcore/db.py", line 701, in __iter__
    objects = self.sort.sort(list(self._get_objects()))
  File "/usr/lib/python3.7/site-packages/beets/dbcore/query.py", line 885, in sort
    return sorted(objs, key=key, reverse=not self.ascending)
TypeError: '<' not supported between instances of 'float' and 'str'

Solution

There is already a TODO in the code for this issue:

# TODO: Conversion and null-detection here. In Python 3,

I guess most - if not all - attribute fields already have a type specified (like the acousticbrainz-plugin here: https://github.com/beetbox/beets/blob/master/beetsplug/acousticbrainz.py#L116).

So we should somehow gather or query them when sorting the objects.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugbugs that are confirmed and actionable

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions