(self)
| 2361 | |
| 2362 | @property |
| 2363 | def orderby_issubset_groupby(self): |
| 2364 | if self.extra_order_by: |
| 2365 | # Raw SQL from extra(order_by=...) can't be reliably compared |
| 2366 | # against resolved OrderBy/Col expressions. Treat as not a subset. |
| 2367 | return False |
| 2368 | if self.group_by in (None, True): |
| 2369 | # There is either no aggregation at all (None), or the group by |
| 2370 | # is generated automatically from model fields (True), in which |
| 2371 | # case the order by is necessarily a subset of them. |
| 2372 | return True |
| 2373 | if not self.order_by: |
| 2374 | # Although an empty set is always a subset, there's no point in |
| 2375 | # clearing ordering when there isn't any. Avoid the clone() below. |
| 2376 | return True |
| 2377 | # Don't pollute the original query (might disrupt joins). |
| 2378 | q = self.clone() |
| 2379 | order_by_set = set() |
| 2380 | for order_by in q.order_by: |
| 2381 | if hasattr(order_by, "resolve_expression"): |
| 2382 | order_by_set.add(order_by.resolve_expression(q)) |
| 2383 | elif order_by == "?": |
| 2384 | # Random ordering can't be compared against group by. |
| 2385 | return False |
| 2386 | else: |
| 2387 | order_by_set.add(F(order_by.removeprefix("-")).resolve_expression(q)) |
| 2388 | return order_by_set.issubset(self.group_by) |
| 2389 | |
| 2390 | def clear_ordering(self, force=False, clear_default=True): |
| 2391 | """ |
nothing calls this directly
no test coverage detected