Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move transaction.atomic contexts to lower level #5790

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions django/db/models/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,7 @@ def update_or_create(self, defaults=None, **kwargs):
for k, v in six.iteritems(defaults):
setattr(obj, k, v)

with transaction.atomic(using=self.db, savepoint=False):
obj.save(using=self.db)
obj.save(using=self.db)
return obj, False

def _create_object_from_params(self, lookup, params):
Expand All @@ -495,8 +494,7 @@ def _create_object_from_params(self, lookup, params):
Used by get_or_create and update_or_create
"""
try:
with transaction.atomic(using=self.db):
obj = self.create(**params)
obj = self.create(**params)
return obj, True
except IntegrityError:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes makes it not obvious at all that the contents of the try/except IntegrityError are properly wrapped in a transaction.

This is necessary to prevent errors on databases which actually enforce transactional integrity on errors like PostgreSQL.

exc_info = sys.exc_info()
Expand Down