From 979e71dd2d4780fc6b81dc4f8a44562d4b057588 Mon Sep 17 00:00:00 2001 From: wisp3rwind <17089248+wisp3rwind@users.noreply.github.com> Date: Sat, 21 Oct 2023 11:14:02 +0200 Subject: [PATCH] library: log parsed query to help with debugging queries that behave unexpectedly --- beets/dbcore/query.py | 26 ++++++++++++++------------ beets/library.py | 5 ++++- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/beets/dbcore/query.py b/beets/dbcore/query.py index 03f85ac77c..9806d5226f 100644 --- a/beets/dbcore/query.py +++ b/beets/dbcore/query.py @@ -166,8 +166,8 @@ def match(self, obj: Model) -> bool: def __repr__(self) -> str: return ( - "{0.__class__.__name__}({0.field!r}, {0.pattern!r}, " - "{0.fast})".format(self) + f"{self.__class__.__name__}({self.field!r}, {self.pattern!r}, " + f"fast={self.fast})" ) def __eq__(self, other) -> bool: @@ -205,7 +205,7 @@ def match(self, obj: Model) -> bool: return obj.get(self.field) is None def __repr__(self) -> str: - return "{0.__class__.__name__}({0.field!r}, {0.fast})".format(self) + return f"{self.__class__.__name__}({self.field!r}, {self.fast})" class StringFieldQuery(FieldQuery[P]): @@ -471,7 +471,7 @@ def clause_with_joiner( return clause, subvals def __repr__(self) -> str: - return "{0.__class__.__name__}({0.subqueries!r})".format(self) + return f"{self.__class__.__name__}({self.subqueries!r})" def __eq__(self, other) -> bool: return super().__eq__(other) and self.subqueries == other.subqueries @@ -511,8 +511,8 @@ def match(self, obj: Model) -> bool: def __repr__(self) -> str: return ( - "{0.__class__.__name__}({0.pattern!r}, {0.fields!r}, " - "{0.query_class.__name__})".format(self) + f"{self.__class__.__name__}({self.pattern!r}, {self.fields!r}, " + f"{self.query_class.__name__})" ) def __eq__(self, other) -> bool: @@ -577,7 +577,7 @@ def match(self, obj: Model) -> bool: return not self.subquery.match(obj) def __repr__(self) -> str: - return "{0.__class__.__name__}({0.subquery!r})".format(self) + return f"{self.__class__.__name__}({self.subquery!r})" def __eq__(self, other) -> bool: return super().__eq__(other) and self.subquery == other.subquery @@ -883,6 +883,9 @@ def __hash__(self) -> int: def __eq__(self, other) -> bool: return type(self) is type(other) + def __repr__(self): + return f"{self.__class__.__name__}()" + class MultipleSort(Sort): """Sort that encapsulates multiple sub-sorts.""" @@ -934,7 +937,7 @@ def sort(self, items): return items def __repr__(self): - return f"MultipleSort({self.sorts!r})" + return f"{self.__class__.__name__}({self.sorts!r})" def __hash__(self): return hash(tuple(self.sorts)) @@ -972,10 +975,9 @@ def key(obj: Model) -> Any: return sorted(objs, key=key, reverse=not self.ascending) def __repr__(self) -> str: - return "<{}: {}{}>".format( - type(self).__name__, - self.field, - "+" if self.ascending else "-", + return ( + f"{self.__class__.__name__}" + f"({self.field!r}, ascending={self.ascending!r})" ) def __hash__(self) -> int: diff --git a/beets/library.py b/beets/library.py index d0019fb809..c70fb6724b 100644 --- a/beets/library.py +++ b/beets/library.py @@ -1518,9 +1518,12 @@ def parse_query_parts(parts, model_cls): case_insensitive = beets.config["sort_case_insensitive"].get(bool) - return dbcore.parse_sorted_query( + query, sort = dbcore.parse_sorted_query( model_cls, parts, prefixes, case_insensitive ) + log.debug("Parsed query: {!r}", query) + log.debug("Parsed sort: {!r}", sort) + return query, sort def parse_query_string(s, model_cls):