Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #12560. Changed validate_unique to stop checking null primary k…

…ey values. Thanks, Honza Král.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12227 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit a2a5602b1937e94b579957c9c2823da48eb69ed9 1 parent 2b2db12
Joseph Kocherhans authored January 14, 2010
2  AUTHORS
@@ -256,7 +256,7 @@ answer newbie questions, and generally made Django that much better:
256 256
     Gasper Koren
257 257
     Martin Kosír <martin@martinkosir.net>
258 258
     Arthur Koziel <http://arthurkoziel.com>
259  
-    Honza Kral <honza.kral@gmail.com>
  259
+    Honza Král <honza.kral@gmail.com>
260 260
     Meir Kriheli <http://mksoft.co.il/>
261 261
     Bruce Kroeze <http://coderseye.com/>
262 262
     krzysiek.pawlik@silvermedia.pl
2  django/db/models/base.py
@@ -715,7 +715,7 @@ def _perform_unique_checks(self, unique_checks):
715 715
             for field_name in unique_check:
716 716
                 f = self._meta.get_field(field_name)
717 717
                 lookup_value = getattr(self, f.attname)
718  
-                if f.null and lookup_value is None:
  718
+                if lookup_value is None:
719 719
                     # no value, skip the lookup
720 720
                     continue
721 721
                 if f.primary_key and not getattr(self, '_adding', False):
22  tests/modeltests/validation/test_unique.py
@@ -43,18 +43,26 @@ def tearDown(self):
43 43
         settings.DEBUG = self._old_debug
44 44
         super(PerformUniqueChecksTest, self).tearDown()
45 45
 
46  
-    def test_primary_key_unique_check_performed_when_adding(self):
47  
-        """Regression test for #12132"""
48  
-        l = len(connection.queries)
  46
+    def test_primary_key_unique_check_not_performed_when_adding_and_pk_not_specified(self):
  47
+        # Regression test for #12560
  48
+        query_count = len(connection.queries)
49 49
         mtv = ModelToValidate(number=10, name='Some Name')
50 50
         setattr(mtv, '_adding', True)
51 51
         mtv.full_clean()
52  
-        self.assertEqual(l+1, len(connection.queries))
  52
+        self.assertEqual(query_count, len(connection.queries))
  53
+
  54
+    def test_primary_key_unique_check_performed_when_adding_and_pk_specified(self):
  55
+        # Regression test for #12560
  56
+        query_count = len(connection.queries)
  57
+        mtv = ModelToValidate(number=10, name='Some Name', id=123)
  58
+        setattr(mtv, '_adding', True)
  59
+        mtv.full_clean()
  60
+        self.assertEqual(query_count + 1, len(connection.queries))
53 61
 
54 62
     def test_primary_key_unique_check_not_performed_when_not_adding(self):
55  
-        """Regression test for #12132"""
56  
-        l = len(connection.queries)
  63
+        # Regression test for #12132
  64
+        query_count= len(connection.queries)
57 65
         mtv = ModelToValidate(number=10, name='Some Name')
58 66
         mtv.full_clean()
59  
-        self.assertEqual(l, len(connection.queries))
  67
+        self.assertEqual(query_count, len(connection.queries))
60 68
 

0 notes on commit a2a5602

Please sign in to comment.
Something went wrong with that request. Please try again.