Skip to content

Commit

Permalink
rebase and fixed issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ipakeev committed May 1, 2024
1 parent fdca620 commit 42e90ce
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Fixed
^^^^^
- Fix `DatetimeField` use '__year' report `'int' object has no attribute 'utcoffset'`. (#1575)
- Fix `bulk_update` when using custom fields. (#1564)
- Fix `get_or_create` method. (#1404)

0.20.1
------
Expand Down
12 changes: 5 additions & 7 deletions tortoise/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
IntegrityError,
OperationalError,
ParamsError,
TransactionManagementError,
)
from tortoise.fields.base import Field
from tortoise.fields.data import IntField
Expand Down Expand Up @@ -1068,7 +1067,6 @@ async def get_or_create(
:param using_db: Specific DB connection to use instead of default bound
:param kwargs: Query parameters.
:raises IntegrityError: If create failed
:raises TransactionManagementError: If transaction error
"""
if not defaults:
defaults = {}
Expand All @@ -1077,13 +1075,13 @@ async def get_or_create(
return await cls.filter(**kwargs).using_db(db).get(), False
except DoesNotExist:
try:
async with in_transaction(connection_name=db.connection_name) as connection:
return await cls.create(using_db=connection, **defaults, **kwargs), True
except (IntegrityError, TransactionManagementError) as exc:
return await cls.create(using_db=db, **defaults, **kwargs), True
except IntegrityError as exc:
try:
return await cls.filter(**kwargs).using_db(db).get(), False
except Exception:
raise exc
except DoesNotExist:
pass
raise exc

@classmethod
def select_for_update(
Expand Down

0 comments on commit 42e90ce

Please sign in to comment.