Parse a query and fetch. If an order specification is present in the query string the `sort` argument is ignored.
(self, model_cls, query, sort=None)
| 122 | # Querying. |
| 123 | |
| 124 | def _fetch(self, model_cls, query, sort=None): |
| 125 | """Parse a query and fetch. |
| 126 | |
| 127 | If an order specification is present in the query string |
| 128 | the `sort` argument is ignored. |
| 129 | """ |
| 130 | # Parse the query, if necessary. |
| 131 | try: |
| 132 | parsed_sort = None |
| 133 | # Query parsing needs the library root, but keeping it scoped here |
| 134 | # avoids leaking one Library's directory into another's work. |
| 135 | with context.music_dir(self.directory): |
| 136 | if isinstance(query, str): |
| 137 | query, parsed_sort = parse_query_string(query, model_cls) |
| 138 | elif isinstance(query, (list, tuple)): |
| 139 | query, parsed_sort = parse_query_parts(query, model_cls) |
| 140 | except dbcore.query.InvalidQueryArgumentValueError as exc: |
| 141 | raise dbcore.InvalidQueryError(query, exc) |
| 142 | |
| 143 | # Any non-null sort specified by the parsed query overrides the |
| 144 | # provided sort. |
| 145 | if parsed_sort and not isinstance(parsed_sort, NullSort): |
| 146 | sort = parsed_sort |
| 147 | |
| 148 | return super()._fetch(model_cls, query, sort) |
| 149 | |
| 150 | @staticmethod |
| 151 | def get_default_album_sort(): |
no test coverage detected