Skip to content

uow session lifetime prolonged #1

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
17 changes: 8 additions & 9 deletions src/app/app_layer/use_cases/cart_items/add_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@ async def execute(self, data: AddItemToCartInputDTO) -> CartOutputDTO:
async def _add_item_to_cart(self, data: AddItemToCartInputDTO) -> CartOutputDTO:
user = await self._auth_system.get_user_data(auth_data=data.auth_data)

async with self._uow(autocommit=True):
async with self._uow(autocommit=False):
cart = await self._uow.carts.retrieve(cart_id=data.cart_id)
await self._uow.commit()

self._check_user_ownership(cart=cart, user=user)
cart = await self._update_cart(cart=cart, data=data)
self._check_user_ownership(cart=cart, user=user)
cart = await self._update_cart(cart=cart, data=data)

await self._uow.commit()

return CartOutputDTO.model_validate(cart)

Expand All @@ -80,9 +83,7 @@ async def _try_to_add_new_item_to_cart(
) -> Cart:
item = await self._try_to_create_item(cart=cart, data=data)
cart.add_new_item(item)

async with self._uow(autocommit=True):
await self._uow.items.add_item(item=item)
await self._uow.items.add_item(item=item)

logger.info(
"Item %s successfully added to cart %s with qty %s",
Expand Down Expand Up @@ -113,9 +114,7 @@ async def _try_to_create_item(

async def _increase_item_qty(self, cart: Cart, item_id: int, qty: Decimal) -> Cart:
item = cart.increase_item_qty(item_id=item_id, qty=qty)

async with self._uow(autocommit=True):
await self._uow.items.update_item(item=item)
await self._uow.items.update_item(item=item)

logger.info(
"Cart %s. Item %s qty successfully increased. Current item qty %s",
Expand Down