Ticket #13864: 13864-r16288.diff

File 13864-r16288.diff, 3.2 KB (added by Ramiro Morales, 13 years ago)

Patch updated to r16288.

  • django/db/models/base.py

    diff --git a/django/db/models/base.py b/django/db/models/base.py
    a b  
    526526                    # It does already exist, so do an UPDATE.
    527527                    if force_update or non_pks:
    528528                        values = [(f, None, (raw and getattr(self, f.attname) or f.pre_save(self, False))) for f in non_pks]
    529                         rows = manager.using(using).filter(pk=pk_val)._update(values)
    530                         if force_update and not rows:
    531                             raise DatabaseError("Forced update did not affect any rows.")
     529                        if values:
     530                            rows = manager.using(using).filter(pk=pk_val)._update(values)
     531                            if force_update and not rows:
     532                                raise DatabaseError("Forced update did not affect any rows.")
    532533                else:
    533534                    record_exists = False
    534535            if not pk_set or not record_exists:
  • tests/modeltests/force_insert_update/models.py

    diff --git a/tests/modeltests/force_insert_update/models.py b/tests/modeltests/force_insert_update/models.py
    a b  
    88    name = models.CharField(max_length = 10)
    99    value = models.IntegerField()
    1010
     11
     12class InheritedCounter(Counter):
     13    tag = models.CharField(max_length=10)
     14
     15
     16class ProxyCounter(Counter):
     17    class Meta:
     18        proxy = True
     19
     20
     21class SubCounter(Counter):
     22    pass
     23
     24
    1125class WithCustomPK(models.Model):
    1226    name = models.IntegerField(primary_key=True)
    1327    value = models.IntegerField()
  • tests/modeltests/force_insert_update/tests.py

    diff --git a/tests/modeltests/force_insert_update/tests.py b/tests/modeltests/force_insert_update/tests.py
    a b  
    11from django.db import transaction, IntegrityError, DatabaseError
    22from django.test import TestCase
    33
    4 from models import Counter, WithCustomPK
     4from models import (Counter, WithCustomPK, InheritedCounter, ProxyCounter,
     5        SubCounter)
    56
    67
    78class ForceTests(TestCase):
    89    def test_force_update(self):
    910        c = Counter.objects.create(name="one", value=1)
     11
    1012        # The normal case
    11 
    1213        c.value = 2
    1314        c.save()
     15
    1416        # Same thing, via an update
    1517        c.value = 3
    1618        c.save(force_update=True)
     
    3638        # the data isn't in the database already.
    3739        obj = WithCustomPK(name=1, value=1)
    3840        self.assertRaises(DatabaseError, obj.save, force_update=True)
     41
     42
     43class InheritanceTests(TestCase):
     44    def test_force_update_on_inherited_model(self):
     45        a = InheritedCounter(name="count", value=1, tag="spam")
     46        a.save()
     47        a.save(force_update=True)
     48
     49    def test_force_update_on_proxy_model(self):
     50        a = ProxyCounter(name="count", value=1)
     51        a.save()
     52        a.save(force_update=True)
     53
     54    def test_force_update_on_inherited_model_without_fields(self):
     55        '''
     56        Issue 13864: force_update fails on subclassed models, if they don't
     57        specify custom fields.
     58        '''
     59        a = SubCounter(name="count", value=1)
     60        a.save()
     61        a.value = 2
     62        a.save(force_update=True)
Back to Top