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

Fix for #4709 #5236

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ htmlcov/
coverage.xml
*,cover
.hypothesis/
.reports/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this, nice!


# Flask stuff:
instance/
Expand Down
4 changes: 2 additions & 2 deletions beets/dbcore/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,8 +1008,8 @@ def order_clause(self) -> str:
if self.case_insensitive:
field = (
"(CASE "
'WHEN TYPEOF({0})="text" THEN LOWER({0}) '
'WHEN TYPEOF({0})="blob" THEN LOWER({0}) '
"WHEN TYPEOF({0})='text' THEN LOWER({0}) "
"WHEN TYPEOF({0})='blob' THEN LOWER({0}) "
"ELSE {0} END)".format(self.field)
)
else:
Expand Down
7 changes: 2 additions & 5 deletions beets/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,8 @@ def order_clause(self):
order = "ASC" if self.ascending else "DESC"
field = "albumartist" if self.album else "artist"
collate = "COLLATE NOCASE" if self.case_insensitive else ""
return (
"(CASE {0}_sort WHEN NULL THEN {0} "
'WHEN "" THEN {0} '
"ELSE {0}_sort END) {1} {2}"
).format(field, collate, order)

return f"COALESCE(NULLIF({field}_sort, ''), {field}) {collate} {order}"

def sort(self, objs):
if self.album:
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ New features:

Bug fixes:

* :bug:`4709`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a small description of the fix?

* :doc:`/plugins/lastimport`: Improve error handling in the `process_tracks` function and enable it to be used with other plugins.
* :doc:`/plugins/spotify`: Improve handling of ConnectionError.
* :doc:`/plugins/deezer`: Improve Deezer plugin error handling and set requests timeout to 10 seconds.
Expand Down
10 changes: 6 additions & 4 deletions test/test_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_store_changes_database_value(self):
self.i.store()
new_year = (
self.lib._connection()
.execute("select year from items where " 'title="the title"')
.execute("select year from items where title = ?", (self.i.title,))
.fetchone()["year"]
)
self.assertEqual(new_year, 1987)
Expand All @@ -70,7 +70,7 @@ def test_store_only_writes_dirty_fields(self):
self.i.store()
new_genre = (
self.lib._connection()
.execute("select genre from items where " 'title="the title"')
.execute("select genre from items where title = ?", (self.i.title,))
.fetchone()["genre"]
)
self.assertEqual(new_genre, original_genre)
Expand Down Expand Up @@ -105,7 +105,8 @@ def test_item_add_inserts_row(self):
new_grouping = (
self.lib._connection()
.execute(
"select grouping from items " 'where composer="the composer"'
"select grouping from items where composer = ?",
(self.i.composer,),
)
.fetchone()["grouping"]
)
Expand All @@ -119,7 +120,8 @@ def test_library_add_path_inserts_row(self):
new_grouping = (
self.lib._connection()
.execute(
"select grouping from items " 'where composer="the composer"'
"select grouping from items where composer = ?",
(self.i.composer,),
)
.fetchone()["grouping"]
)
Expand Down
Loading