Fixed #22540 -- Made _create_object_from_params() call create()

So as the save step is centralized in create(), especially useful
when customizing behavior in subclasses.
Thanks craig.labenz@gmail.com for the report.
This commit is contained in:
Claude Paroz 2014-05-02 09:06:15 +02:00
parent c8d257e81d
commit 0dce44e16b
1 changed files with 3 additions and 4 deletions

View File

@ -364,6 +364,7 @@ class QuerySet(object):
""" """
obj = self.model(**kwargs) obj = self.model(**kwargs)
self._for_write = True self._for_write = True
with transaction.atomic(using=self.db):
obj.save(force_insert=True, using=self.db) obj.save(force_insert=True, using=self.db)
return obj return obj
@ -446,10 +447,8 @@ class QuerySet(object):
Tries to create an object using passed params. Tries to create an object using passed params.
Used by get_or_create and update_or_create Used by get_or_create and update_or_create
""" """
obj = self.model(**params)
try: try:
with transaction.atomic(using=self.db): obj = self.create(**params)
obj.save(force_insert=True, using=self.db)
return obj, True return obj, True
except IntegrityError: except IntegrityError:
exc_info = sys.exc_info() exc_info = sys.exc_info()