Ticket #12560: 12560.diff

File 12560.diff, 1.8 KB (added by Honza Král, 15 years ago)

Quick fix to get the discussion started, may not be 100%

  • django/db/models/base.py

    diff --git a/django/db/models/base.py b/django/db/models/base.py
    index 06db7cc..dcc1ca2 100644
    a b class Model(object):  
    696696            for field_name in unique_check:
    697697                f = self._meta.get_field(field_name)
    698698                lookup_value = getattr(self, f.attname)
    699                 if f.null and lookup_value is None:
     699                if lookup_value is None:
    700700                    # no value, skip the lookup
    701701                    continue
    702702                if f.primary_key and not getattr(self, '_adding', False):
  • tests/modeltests/validation/test_unique.py

    diff --git a/tests/modeltests/validation/test_unique.py b/tests/modeltests/validation/test_unique.py
    index cbb56aa..8ae946c 100644
    a b class PerformUniqueChecksTest(unittest.TestCase):  
    4242        settings.DEBUG = self._old_debug
    4343        super(PerformUniqueChecksTest, self).tearDown()
    4444
    45     def test_primary_key_unique_check_performed_when_adding(self):
     45    def test_primary_key_unique_check_not_performed_when_adding_and_pk_not_specified(self):
    4646        """Regression test for #12132"""
    4747        l = len(connection.queries)
    4848        mtv = ModelToValidate(number=10, name='Some Name')
    4949        setattr(mtv, '_adding', True)
    5050        mtv.full_validate()
     51        self.assertEqual(l, len(connection.queries))
     52
     53    def test_primary_key_unique_check_performed_when_adding_and_pk_specified(self):
     54        """Regression test for #12132"""
     55        l = len(connection.queries)
     56        mtv = ModelToValidate(number=10, name='Some Name', id=123)
     57        setattr(mtv, '_adding', True)
     58        mtv.full_validate()
    5159        self.assertEqual(l+1, len(connection.queries))
    5260
    5361    def test_primary_key_unique_check_not_performed_when_not_adding(self):
Back to Top