Author: kmtracey
Date: 2011-11-12 11:06:39 -0800 (Sat, 12 Nov 2011)
New Revision: 17088
Modified:
django/trunk/AUTHORS
django/trunk/django/db/models/base.py
django/trunk/tests/modeltests/force_insert_update/models.py
django/trunk/tests/modeltests/force_insert_update/tests.py
Log:
Fix #13864: Removed database error raised when force_update is requsted on save
of an inherited model with no fields of its own. Thanks fva, gregmuellegger,
and markb1.
Modified: django/trunk/AUTHORS
===================================================================
--- django/trunk/AUTHORS 2011-11-12 18:50:50 UTC (rev 17087)
+++ django/trunk/AUTHORS 2011-11-12 19:06:39 UTC (rev 17088)
@@ -87,6 +87,7 @@
Julian Bez
Arvis Bickovskis <[email protected]>
Natalia Bidart <[email protected]>
+ Mark Biggers <[email protected]>
Paul Bissex <http://e-scribe.com/>
Simon Blanchard
David Blewett <[email protected]>
Modified: django/trunk/django/db/models/base.py
===================================================================
--- django/trunk/django/db/models/base.py 2011-11-12 18:50:50 UTC (rev
17087)
+++ django/trunk/django/db/models/base.py 2011-11-12 19:06:39 UTC (rev
17088)
@@ -526,9 +526,10 @@
# It does already exist, so do an UPDATE.
if force_update or non_pks:
values = [(f, None, (raw and getattr(self, f.attname)
or f.pre_save(self, False))) for f in non_pks]
- rows =
manager.using(using).filter(pk=pk_val)._update(values)
- if force_update and not rows:
- raise DatabaseError("Forced update did not affect
any rows.")
+ if values:
+ rows =
manager.using(using).filter(pk=pk_val)._update(values)
+ if force_update and not rows:
+ raise DatabaseError("Forced update did not
affect any rows.")
else:
record_exists = False
if not pk_set or not record_exists:
Modified: django/trunk/tests/modeltests/force_insert_update/models.py
===================================================================
--- django/trunk/tests/modeltests/force_insert_update/models.py 2011-11-12
18:50:50 UTC (rev 17087)
+++ django/trunk/tests/modeltests/force_insert_update/models.py 2011-11-12
19:06:39 UTC (rev 17088)
@@ -9,6 +9,16 @@
name = models.CharField(max_length = 10)
value = models.IntegerField()
+class InheritedCounter(Counter):
+ tag = models.CharField(max_length=10)
+
+class ProxyCounter(Counter):
+ class Meta:
+ proxy = True
+
+class SubCounter(Counter):
+ pass
+
class WithCustomPK(models.Model):
name = models.IntegerField(primary_key=True)
value = models.IntegerField()
Modified: django/trunk/tests/modeltests/force_insert_update/tests.py
===================================================================
--- django/trunk/tests/modeltests/force_insert_update/tests.py 2011-11-12
18:50:50 UTC (rev 17087)
+++ django/trunk/tests/modeltests/force_insert_update/tests.py 2011-11-12
19:06:39 UTC (rev 17088)
@@ -3,14 +3,15 @@
from django.db import transaction, IntegrityError, DatabaseError
from django.test import TestCase
-from .models import Counter, WithCustomPK
+from .models import (Counter, WithCustomPK, InheritedCounter, ProxyCounter,
+ SubCounter)
class ForceTests(TestCase):
def test_force_update(self):
c = Counter.objects.create(name="one", value=1)
+
# The normal case
-
c.value = 2
c.save()
# Same thing, via an update
@@ -38,3 +39,25 @@
# the data isn't in the database already.
obj = WithCustomPK(name=1, value=1)
self.assertRaises(DatabaseError, obj.save, force_update=True)
+
+
+class InheritanceTests(TestCase):
+ def test_force_update_on_inherited_model(self):
+ a = InheritedCounter(name="count", value=1, tag="spam")
+ a.save()
+ a.save(force_update=True)
+
+ def test_force_update_on_proxy_model(self):
+ a = ProxyCounter(name="count", value=1)
+ a.save()
+ a.save(force_update=True)
+
+ def test_force_update_on_inherited_model_without_fields(self):
+ '''
+ Issue 13864: force_update fails on subclassed models, if they don't
+ specify custom fields.
+ '''
+ a = SubCounter(name="count", value=1)
+ a.save()
+ a.value = 2
+ a.save(force_update=True)
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.