summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
Diffstat (limited to 'django')
-rw-r--r--django/core/exceptions.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/django/core/exceptions.py b/django/core/exceptions.py
index dc084b8692..2b3e55fe49 100644
--- a/django/core/exceptions.py
+++ b/django/core/exceptions.py
@@ -1,6 +1,9 @@
"""
Global Django exception and warning classes.
"""
+import operator
+
+from django.utils.hashable import make_hashable
class FieldDoesNotExist(Exception):
@@ -182,6 +185,23 @@ class ValidationError(Exception):
def __repr__(self):
return 'ValidationError(%s)' % self
+ def __eq__(self, other):
+ if not isinstance(other, ValidationError):
+ return NotImplemented
+ return hash(self) == hash(other)
+
+ def __hash__(self):
+ # Ignore params and messages ordering.
+ if hasattr(self, 'message'):
+ return hash((
+ self.message,
+ self.code,
+ tuple(sorted(make_hashable(self.params))) if self.params else None,
+ ))
+ if hasattr(self, 'error_dict'):
+ return hash(tuple(sorted(make_hashable(self.error_dict))))
+ return hash(tuple(sorted(self.error_list, key=operator.attrgetter('message'))))
+
class EmptyResultSet(Exception):
"""A database query predicate is impossible."""