Skip to content

Commit

Permalink
Update models.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangying000 authored Apr 10, 2024
1 parent 0c8efde commit 7488f13
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tortoise/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,11 @@ async def get_or_create(
)
except DoesNotExist:
try:
return await cls.create(using_db=connection, **defaults, **kwargs), True
merged_defaults = {**defaults, **kwargs}
return (
await cls.create(using_db=connection, **merged_defaults),
True,
)
except (IntegrityError, TransactionManagementError):
return await cls.filter(**kwargs).using_db(connection).get(), False

Expand Down

0 comments on commit 7488f13

Please sign in to comment.