Ticket #13864: r17083.diff

File r17083.diff, 3.4 KB (added by markb1, 12 years ago)
  • django/db/models/base.py

    diff --git a/django/db/models/base.py b/django/db/models/base.py
    index b5ce39e..ebd67be 100644
    a b class Model(object):  
    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
    index db4c5d2..c356312 100644
    a b class Counter(models.Model):  
    99    name = models.CharField(max_length = 10)
    1010    value = models.IntegerField()
    1111
     12class InheritedCounter(Counter):
     13    tag = models.CharField(max_length=10)
     14
     15class ProxyCounter(Counter):
     16    class Meta:
     17        proxy = True
     18
     19class SubCounter(Counter):
     20    pass
     21
    1222class WithCustomPK(models.Model):
    1323    name = models.IntegerField(primary_key=True)
    1424    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
    index ea0e55f..a5b2dce 100644
    a b from __future__ import absolute_import  
    33from django.db import transaction, IntegrityError, DatabaseError
    44from django.test import TestCase
    55
    6 from .models import Counter, WithCustomPK
     6from .models import (Counter, WithCustomPK, InheritedCounter, ProxyCounter,
     7                     SubCounter)
    78
    89
    910class ForceTests(TestCase):
    1011    def test_force_update(self):
    1112        c = Counter.objects.create(name="one", value=1)
    12         # The normal case
    1313
     14        # The normal case
    1415        c.value = 2
    1516        c.save()
    1617        # Same thing, via an update
    class ForceTests(TestCase):  
    3839        # the data isn't in the database already.
    3940        obj = WithCustomPK(name=1, value=1)
    4041        self.assertRaises(DatabaseError, obj.save, force_update=True)
     42
     43
     44class InheritanceTests(TestCase):
     45    def test_force_update_on_inherited_model(self):
     46        a = InheritedCounter(name="count", value=1, tag="spam")
     47        a.save()
     48        a.save(force_update=True)
     49
     50    def test_force_update_on_proxy_model(self):
     51        a = ProxyCounter(name="count", value=1)
     52        a.save()
     53        a.save(force_update=True)
     54
     55    def test_force_update_on_inherited_model_without_fields(self):
     56        '''
     57        Issue 13864: force_update fails on subclassed models, if they don't
     58        specify custom fields.
     59        '''
     60        a = SubCounter(name="count", value=1)
     61        a.save()
     62        a.value = 2
     63        a.save(force_update=True)
Back to Top