Code

Ticket #16134: 16134_fix.diff

File 16134_fix.diff, 1.3 KB (added by RoboHamburger, 3 years ago)

Patch that adds regression test and fix.

Line 
1Index: tests/regressiontests/model_fields/tests.py
2===================================================================
3--- tests/regressiontests/model_fields/tests.py (revision 16308)
4+++ tests/regressiontests/model_fields/tests.py (working copy)
5@@ -23,6 +23,15 @@
6 
7 
8 class BasicFieldTests(test.TestCase):
9+    def test_field_can_compare_null(self):
10+        """
11+        Regression test for #16134. Checks to see if a field can be compared with None.
12+        """
13+        field = models.Field()
14+       
15+        self.assertNotEqual(field,None)
16+        self.assertNotEqual(cmp(field,None),0)
17+   
18     def test_show_hidden_initial(self):
19         """
20         Regression test for #12913. Make sure fields with choices respect
21Index: django/db/models/fields/__init__.py
22===================================================================
23--- django/db/models/fields/__init__.py (revision 16308)
24+++ django/db/models/fields/__init__.py (working copy)
25@@ -117,6 +117,8 @@
26         self.error_messages = messages
27 
28     def __cmp__(self, other):
29+        if not hasattr(other, 'creation_counter'):
30+            return super(self).cmp(self, other)
31         # This is needed because bisect does not take a comparison function.
32         return cmp(self.creation_counter, other.creation_counter)
33