summaryrefslogtreecommitdiff
path: root/django/db/models/sql/datastructures.py
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2020-10-25 17:41:06 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-10-28 07:21:53 +0100
commitbbf141bcdc31f1324048af9233583a523ac54c94 (patch)
tree0babf338ba1a5d8c5f5710a777eea60dd3b9aa3d /django/db/models/sql/datastructures.py
parent556fa4bbba5ba86bc1646a86fb11ab55405d4aa4 (diff)
Refs #27149 -- Fixed sql.Query identity.
By making Query subclass BaseExpression in 35431298226165986ad07e91f9d3aca721ff38ec the former defined it's identity based off _construct_args which is not appropriate.
Diffstat (limited to 'django/db/models/sql/datastructures.py')
-rw-r--r--django/db/models/sql/datastructures.py43
1 files changed, 31 insertions, 12 deletions
diff --git a/django/db/models/sql/datastructures.py b/django/db/models/sql/datastructures.py
index c2c347b3cf..c9598b3bd4 100644
--- a/django/db/models/sql/datastructures.py
+++ b/django/db/models/sql/datastructures.py
@@ -114,17 +114,28 @@ class Join:
self.join_field, self.nullable, filtered_relation=filtered_relation,
)
- def equals(self, other, with_filtered_relation):
+ @property
+ def identity(self):
return (
- isinstance(other, self.__class__) and
- self.table_name == other.table_name and
- self.parent_alias == other.parent_alias and
- self.join_field == other.join_field and
- (not with_filtered_relation or self.filtered_relation == other.filtered_relation)
+ self.__class__,
+ self.table_name,
+ self.parent_alias,
+ self.join_field,
+ self.filtered_relation,
)
def __eq__(self, other):
- return self.equals(other, with_filtered_relation=True)
+ if not isinstance(other, Join):
+ return NotImplemented
+ return self.identity == other.identity
+
+ def __hash__(self):
+ return hash(self.identity)
+
+ def equals(self, other, with_filtered_relation):
+ if with_filtered_relation:
+ return self == other
+ return self.identity[:-1] == other.identity[:-1]
def demote(self):
new = self.relabeled_clone({})
@@ -160,9 +171,17 @@ class BaseTable:
def relabeled_clone(self, change_map):
return self.__class__(self.table_name, change_map.get(self.table_alias, self.table_alias))
+ @property
+ def identity(self):
+ return self.__class__, self.table_name, self.table_alias
+
+ def __eq__(self, other):
+ if not isinstance(other, BaseTable):
+ return NotImplemented
+ return self.identity == other.identity
+
+ def __hash__(self):
+ return hash(self.identity)
+
def equals(self, other, with_filtered_relation):
- return (
- isinstance(self, other.__class__) and
- self.table_name == other.table_name and
- self.table_alias == other.table_alias
- )
+ return self.identity == other.identity