From 19e20a2a3f763388bba9263d56db34012e90cf5b Mon Sep 17 00:00:00 2001 From: Adam Chainz Date: Fri, 5 Aug 2016 14:18:12 +0100 Subject: [PATCH] Fixed crash comparing CheckMessage objects to non-CheckMessage objects. --- django/core/checks/messages.py | 7 +++++-- tests/check_framework/tests.py | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/django/core/checks/messages.py b/django/core/checks/messages.py index 23e9d5a794..345ebec1e1 100644 --- a/django/core/checks/messages.py +++ b/django/core/checks/messages.py @@ -23,8 +23,11 @@ class CheckMessage(object): self.id = id def __eq__(self, other): - return all(getattr(self, attr) == getattr(other, attr) - for attr in ['level', 'msg', 'hint', 'obj', 'id']) + return ( + isinstance(other, self.__class__) and + all(getattr(self, attr) == getattr(other, attr) + for attr in ['level', 'msg', 'hint', 'obj', 'id']) + ) def __ne__(self, other): return not (self == other) diff --git a/tests/check_framework/tests.py b/tests/check_framework/tests.py index 9f4294793d..4748f28eeb 100644 --- a/tests/check_framework/tests.py +++ b/tests/check_framework/tests.py @@ -124,6 +124,10 @@ class MessageTests(SimpleTestCase): e2 = Error("Error2", obj=SimpleModel) self.assertNotEqual(e1, e2) + def test_not_equal_to_non_check(self): + e = Error("Error", obj=DummyObj()) + self.assertNotEqual(e, 'a string') + def simple_system_check(**kwargs): simple_system_check.kwargs = kwargs