Changed create() and get_or_create() to force an insert (not update an existing value).

Backwards incompatible if you are using manually-specific primary key values
and relying on the previously documented behaviour that the new values would
always exist in the database (i.e. it would update the existing entry).

Fixed #8419.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@8670 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2008-08-28 17:18:05 +00:00
parent 79348d4018
commit c181734fa1
3 changed files with 25 additions and 5 deletions

View file

@ -308,7 +308,7 @@ class QuerySet(object):
and returning the created object.
"""
obj = self.model(**kwargs)
obj.save()
obj.save(force_insert=True)
return obj
def get_or_create(self, **kwargs):
@ -328,7 +328,7 @@ class QuerySet(object):
params.update(defaults)
obj = self.model(**params)
sid = transaction.savepoint()
obj.save()
obj.save(force_insert=True)
transaction.savepoint_commit(sid)
return obj, True
except IntegrityError, e: