Fix AttributeError on g.cart in product cart route
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 42s

g.cart was never populated in the market app — the cart loader
before_request hook was only registered in the cart microservice.
Replace the dead filter-building code with an actual query that
loads cart items inline, scoped to the current user/session.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
giles
2026-02-15 10:11:49 +00:00
parent 039386b6e7
commit 44f475857b

View File

@@ -192,11 +192,23 @@ def register():
ident = current_cart_identity()
filters = [CartItem.deleted_at.is_(None), CartItem.product_id == product_id]
# Load cart items for current user/session
from sqlalchemy.orm import selectinload
cart_filters = [CartItem.deleted_at.is_(None)]
if ident["user_id"] is not None:
filters.append(CartItem.user_id == ident["user_id"])
cart_filters.append(CartItem.user_id == ident["user_id"])
else:
filters.append(CartItem.session_id == ident["session_id"])
cart_filters.append(CartItem.session_id == ident["session_id"])
cart_result = await g.s.execute(
select(CartItem)
.where(*cart_filters)
.order_by(CartItem.created_at.desc())
.options(
selectinload(CartItem.product),
selectinload(CartItem.market_place),
)
)
g.cart = list(cart_result.scalars().all())
ci = next(
(item for item in g.cart if item.product_id == product_id),