Skip to content

Commit

Permalink
library: log parsed query
Browse files Browse the repository at this point in the history
to help with debugging queries that behave unexpectedly
  • Loading branch information
wisp3rwind committed Oct 22, 2023
1 parent 5dee3e6 commit d828f99
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
27 changes: 14 additions & 13 deletions beets/dbcore/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ def match(self, obj: Model) -> bool:
return self.value_match(self.pattern, obj.get(self.field))

def __repr__(self) -> str:
return ("{0.__class__.__name__}({0.field!r}, {0.pattern!r}, "
"{0.fast})".format(self))
return (f"{self.__class__.__name__}({self.field!r}, {self.pattern!r}, "
f"fast={self.fast})")

def __eq__(self, other) -> bool:
return super().__eq__(other) and \
Expand Down Expand Up @@ -202,7 +202,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]):
Expand Down Expand Up @@ -464,7 +464,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 \
Expand Down Expand Up @@ -504,8 +504,10 @@ def match(self, obj: Model) -> bool:
return False

def __repr__(self) -> str:
return ("{0.__class__.__name__}({0.pattern!r}, {0.fields!r}, "
"{0.query_class.__name__})".format(self))
return (
f"{self.__class__.__name__}({self.pattern!r}, {self.fields!r}, "
f"{self.query_class.__name__})"
)

def __eq__(self, other) -> bool:
return super().__eq__(other) and \
Expand Down Expand Up @@ -569,7 +571,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 \
Expand Down Expand Up @@ -870,6 +872,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.
Expand Down Expand Up @@ -922,7 +927,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))
Expand Down Expand Up @@ -961,11 +966,7 @@ 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__}({self.field!r}, {self.ascending!r})"

def __hash__(self) -> int:
return hash((self.field, self.ascending))
Expand Down
5 changes: 4 additions & 1 deletion beets/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -1457,9 +1457,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(f"Parsed query: {query!r}")
log.debug(f"Parsed sort: {sort!r}")
return query, sort


def parse_query_string(s, model_cls):
Expand Down

0 comments on commit d828f99

Please sign in to comment.