Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
@jkocherhans jkocherhans authored
View
2  AUTHORS
@@ -256,7 +256,7 @@ answer newbie questions, and generally made Django that much better:
Gasper Koren
Martin Kosír <martin@martinkosir.net>
Arthur Koziel <http://arthurkoziel.com>
- Honza Kral <honza.kral@gmail.com>
+ Honza Král <honza.kral@gmail.com>
Meir Kriheli <http://mksoft.co.il/>
Bruce Kroeze <http://coderseye.com/>
krzysiek.pawlik@silvermedia.pl
View
2  django/db/models/base.py
@@ -715,7 +715,7 @@ def _perform_unique_checks(self, unique_checks):
for field_name in unique_check:
f = self._meta.get_field(field_name)
lookup_value = getattr(self, f.attname)
- if f.null and lookup_value is None:
+ if lookup_value is None:
# no value, skip the lookup
continue
if f.primary_key and not getattr(self, '_adding', False):
View
22 tests/modeltests/validation/test_unique.py
@@ -43,18 +43,26 @@ def tearDown(self):
settings.DEBUG = self._old_debug
super(PerformUniqueChecksTest, self).tearDown()
- def test_primary_key_unique_check_performed_when_adding(self):
- """Regression test for #12132"""
- l = len(connection.queries)
+ def test_primary_key_unique_check_not_performed_when_adding_and_pk_not_specified(self):
+ # Regression test for #12560
+ query_count = len(connection.queries)
mtv = ModelToValidate(number=10, name='Some Name')
setattr(mtv, '_adding', True)
mtv.full_clean()
- self.assertEqual(l+1, len(connection.queries))
+ self.assertEqual(query_count, len(connection.queries))
+
+ def test_primary_key_unique_check_performed_when_adding_and_pk_specified(self):
+ # Regression test for #12560
+ query_count = len(connection.queries)
+ mtv = ModelToValidate(number=10, name='Some Name', id=123)
+ setattr(mtv, '_adding', True)
+ mtv.full_clean()
+ self.assertEqual(query_count + 1, len(connection.queries))
def test_primary_key_unique_check_not_performed_when_not_adding(self):
- """Regression test for #12132"""
- l = len(connection.queries)
+ # Regression test for #12132
+ query_count= len(connection.queries)
mtv = ModelToValidate(number=10, name='Some Name')
mtv.full_clean()
- self.assertEqual(l, len(connection.queries))
+ self.assertEqual(query_count, len(connection.queries))
Please sign in to comment.
Something went wrong with that request. Please try again.