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