Ticket #10967: patch_vanschelven

File patch_vanschelven, 2.3 KB (added by Klaas van Schelven, 14 years ago)

Patch w/ fix & tests

Line 
1# HG changeset patch
2# User Klaas van Schelven <klaas@vanschelven.com>
3# Date 1295019289 -3600
4# Node ID cf2ca886591242f0779d63b923e644fab062827b
5# Parent 3ca2d76121b7532ee490f5ce00ae91bc0c344cd8
6Fix for #10967
7
8diff -r 3ca2d76121b7 -r cf2ca8865912 django/db/models/base.py
9--- a/django/db/models/base.py Fri Jan 14 08:31:14 2011 +0000
10+++ b/django/db/models/base.py Fri Jan 14 16:34:49 2011 +0100
11@@ -522,7 +522,7 @@
12 if force_update or non_pks:
13 values = [(f, None, (raw and getattr(self, f.attname) or f.pre_save(self, False))) for f in non_pks]
14 rows = manager.using(using).filter(pk=pk_val)._update(values)
15- if force_update and not rows:
16+ if force_update and values and not rows:
17 raise DatabaseError("Forced update did not affect any rows.")
18 else:
19 record_exists = False
20diff -r 3ca2d76121b7 -r cf2ca8865912 tests/modeltests/force_insert_update/models.py
21--- a/tests/modeltests/force_insert_update/models.py Fri Jan 14 08:31:14 2011 +0000
22+++ b/tests/modeltests/force_insert_update/models.py Fri Jan 14 16:34:49 2011 +0100
23@@ -8,6 +8,9 @@
24 name = models.CharField(max_length = 10)
25 value = models.IntegerField()
26
27+class Subclass(Counter):
28+ pass
29+
30 class WithCustomPK(models.Model):
31 name = models.IntegerField(primary_key=True)
32 value = models.IntegerField()
33diff -r 3ca2d76121b7 -r cf2ca8865912 tests/modeltests/force_insert_update/tests.py
34--- a/tests/modeltests/force_insert_update/tests.py Fri Jan 14 08:31:14 2011 +0000
35+++ b/tests/modeltests/force_insert_update/tests.py Fri Jan 14 16:34:49 2011 +0100
36@@ -1,7 +1,7 @@
37 from django.db import transaction, IntegrityError, DatabaseError
38 from django.test import TestCase
39
40-from models import Counter, WithCustomPK
41+from models import Counter, WithCustomPK, Subclass
42
43
44 class ForceTests(TestCase):
45@@ -36,3 +36,10 @@
46 # the data isn't in the database already.
47 obj = WithCustomPK(name=1, value=1)
48 self.assertRaises(DatabaseError, obj.save, force_update=True)
49+
50+ subclass = Subclass(name="one", value=1)
51+ subclass.save()
52+ subclass.name = "updated"
53+ subclass.save(force_update=True)
54+
55+ self.fail()
Back to Top