mirror of
https://github.com/django/django.git
synced 2025-08-09 05:18:56 +00:00
Subquery deconstruction support required implementing complex and
expensive equality rules for sql.Query objects for little benefit as
the latter cannot themselves be made deconstructible to their reference
to model classes.
Making Expression @deconstructible and not BaseExpression allows
interested parties to conform to the "expression" API even if they are
not deconstructible as it's only a requirement for expressions allowed
in Model fields and meta options (e.g. constraints, indexes).
Thanks Phillip Cutter for the report.
This also fixes a performance regression in bbf141bcdc
.
This commit is contained in:
parent
4f600673d7
commit
c8b6594305
6 changed files with 31 additions and 65 deletions
|
@ -5,6 +5,7 @@ Factored out from django.db.models.query to avoid making the main module very
|
|||
large and/or so that they can be used by other modules without getting into
|
||||
circular import difficulties.
|
||||
"""
|
||||
import copy
|
||||
import functools
|
||||
import inspect
|
||||
from collections import namedtuple
|
||||
|
@ -43,14 +44,11 @@ class Q(tree.Node):
|
|||
if not(isinstance(other, Q) or getattr(other, 'conditional', False) is True):
|
||||
raise TypeError(other)
|
||||
|
||||
# If the other Q() is empty, ignore it and just use `self`.
|
||||
if not other:
|
||||
if not self:
|
||||
return other.copy() if hasattr(other, 'copy') else copy.copy(other)
|
||||
elif isinstance(other, Q) and not other:
|
||||
_, args, kwargs = self.deconstruct()
|
||||
return type(self)(*args, **kwargs)
|
||||
# Or if this Q is empty, ignore it and just use `other`.
|
||||
elif not self:
|
||||
_, args, kwargs = other.deconstruct()
|
||||
return type(other)(*args, **kwargs)
|
||||
|
||||
obj = type(self)()
|
||||
obj.connector = conn
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue