Skip to content

Commit

Permalink
Fix 500 error on parallel same-object creates
Browse files Browse the repository at this point in the history
fixes: pulp#4183
  • Loading branch information
gerrod3 committed Aug 2, 2023
1 parent be1400f commit 43a7bc8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES/4183.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed a 500 server error when two concurrent requests try to create an object with the same unique fields.
10 changes: 10 additions & 0 deletions pulpcore/app/serializers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,16 @@ def _validate_relative_path(self, path):

return path

def save(self, **kwargs):
try:
return super().save(**kwargs)
except IntegrityError as e:
# Concurrent request got by the unique validator on the serializer
if "unique" in str(e):
# Run validation again to properly raise an unique-ValidationError
self.run_validation(self.initial_data)
raise e

def __init_subclass__(cls, **kwargs):
"""Set default attributes in subclasses.
Expand Down

0 comments on commit 43a7bc8

Please sign in to comment.