Ticket #8419: get_or_create.race_patch

File get_or_create.race_patch, 1.5 KB (added by Richard Davies <richard.davies@…>, 16 years ago)
Line 
1diff -uNr a/django/db/models/query.py b/django/db/models/query.py
2--- a/django/db/models/query.py 2008-08-19 16:20:15.000000000 +0100
3+++ b/django/db/models/query.py 2008-08-19 16:21:13.000000000 +0100
4@@ -327,7 +327,7 @@
5 params.update(defaults)
6 obj = self.model(**params)
7 sid = transaction.savepoint()
8- obj.save()
9+ obj.save(force_insert=True)
10 transaction.savepoint_commit(sid)
11 return obj, True
12 except IntegrityError, e:
13diff -uNr a/docs/db-api.txt b/docs/db-api.txt
14--- a/docs/db-api.txt 2008-08-19 16:20:36.000000000 +0100
15+++ b/docs/db-api.txt 2008-08-19 16:24:05.000000000 +0100
16@@ -1174,7 +1174,7 @@
17 obj = Person.objects.get(first_name='John', last_name='Lennon')
18 except Person.DoesNotExist:
19 obj = Person(first_name='John', last_name='Lennon', birthday=date(1940, 10, 9))
20- obj.save()
21+ obj.save(force_insert=True)
22
23 This pattern gets quite unwieldy as the number of fields in a model goes up.
24 The above example can be rewritten using ``get_or_create()`` like so::
25@@ -1193,7 +1193,7 @@
26 params = dict([(k, v) for k, v in kwargs.items() if '__' not in k])
27 params.update(defaults)
28 obj = self.model(**params)
29- obj.save()
30+ obj.save(force_insert=True)
31
32 In English, that means start with any non-``'defaults'`` keyword argument that
33 doesn't contain a double underscore (which would indicate a non-exact lookup).
Back to Top