Ticket #13864: 13864.tests_and_possible_fix.patch

File 13864.tests_and_possible_fix.patch, 2.6 KB (added by Gregor Müllegger, 14 years ago)

Patch with tests and a possible, simple fix.

  • django/db/models/base.py

    === modified file 'django/db/models/base.py'
     
    498498                    # It does already exist, so do an UPDATE.
    499499                    if force_update or non_pks:
    500500                        values = [(f, None, (raw and getattr(self, f.attname) or f.pre_save(self, False))) for f in non_pks]
    501                         rows = manager.using(using).filter(pk=pk_val)._update(values)
    502                         if force_update and not rows:
    503                             raise DatabaseError("Forced update did not affect any rows.")
     501                        if values:
     502                            rows = manager.using(using).filter(pk=pk_val)._update(values)
     503                            if force_update and not rows:
     504                                raise DatabaseError("Forced update did not affect any rows.")
    504505                else:
    505506                    record_exists = False
    506507            if not pk_set or not record_exists:
  • tests/modeltests/force_insert_update/models.py

    === modified file 'tests/modeltests/force_insert_update/models.py'
     
    33automatic behaviour).
    44"""
    55from django.db import models, transaction, IntegrityError
     6from django.test import TestCase
    67
    78class Counter(models.Model):
    8     name = models.CharField(max_length = 10)
     9    name = models.CharField(max_length=10)
    910    value = models.IntegerField()
    1011
     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
    1122class WithCustomPK(models.Model):
    1223    name = models.IntegerField(primary_key=True)
    1324    value = models.IntegerField()
    1425
     26class InheritanceTests(TestCase):
     27    def test_force_update_on_inherited_model(self):
     28        a = InheritedCounter(name="count", value=1, tag="spam")
     29        a.save()
     30        a.save(force_update=True)
     31
     32    def test_force_update_on_proxy_model(self):
     33        a = ProxyCounter(name="count", value=1)
     34        a.save()
     35        a.save(force_update=True)
     36
     37    def test_force_update_on_inherited_model_without_fields(self):
     38        '''
     39        Issue 13864: force_update fails on subclassed models, if they don't
     40        specify custom fields.
     41        '''
     42        a = SubCounter(name="count", value=1)
     43        a.save()
     44        a.value = 2
     45        a.save(force_update=True)
     46
    1547__test__ = {"API_TESTS": """
    1648>>> c = Counter.objects.create(name="one", value=1)
    1749
Back to Top