Fixed #12560. Changed validate_unique to stop checking null primary key values. Thanks, Honza Král.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12227 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
2b2db12032
commit
a2a5602b19
2
AUTHORS
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
|
||||
|
|
|
@ -715,7 +715,7 @@ class Model(object):
|
|||
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):
|
||||
|
|
|
@ -43,18 +43,26 @@ class PerformUniqueChecksTest(unittest.TestCase):
|
|||
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))
|
||||
|
||||
|
|
Loading…
Reference in New Issue