Fix stale cart count: commit transaction before cross-service fragment fetch

The cart-mini fragment relies on cart calling back to events for calendar/
ticket counts. Without committing first, the callback runs in a separate
transaction and misses the just-added entry or ticket adjustment.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-27 10:30:13 +00:00
parent bcac8e5adc
commit 0c4682e4d7
3 changed files with 11 additions and 17 deletions

View File

@@ -125,7 +125,10 @@ def register() -> Blueprint:
# Load entry DTO for the widget template
entry = await services.calendar.entry_by_id(g.s, entry_id)
# Fetch OOB cart-mini fragment from cart service
# Commit so cross-service calls see the updated tickets
await g.tx.commit()
g.tx = await g.s.begin()
from shared.infrastructure.fragments import fetch_fragment
frag_params = {"oob": "1"}
if ident["user_id"] is not None:

View File

@@ -8,9 +8,6 @@ from quart import (
)
from sqlalchemy import update, func as sa_func
from models.calendars import CalendarEntry
from .services.entries import (
@@ -206,18 +203,9 @@ def register():
entry.ticket_price = ticket_price
entry.ticket_count = ticket_count
# Count pending calendar entries from local session (sees the just-added entry)
user_id = getattr(g, "user", None) and g.user.id
cal_filters = [
CalendarEntry.deleted_at.is_(None),
CalendarEntry.state == "pending",
]
if user_id:
cal_filters.append(CalendarEntry.user_id == user_id)
cal_count = await g.s.scalar(
select(sa_func.count()).select_from(CalendarEntry).where(*cal_filters)
) or 0
# Commit so cross-service calls see the new entry
await g.tx.commit()
g.tx = await g.s.begin()
from shared.infrastructure.cart_identity import current_cart_identity
from shared.infrastructure.fragments import fetch_fragment

View File

@@ -106,7 +106,10 @@ def register() -> Blueprint:
# Load entry DTO for the widget template
entry = await services.calendar.entry_by_id(g.s, entry_id)
# Fetch OOB cart-mini fragment from cart service
# Commit so cross-service calls see the updated tickets
await g.tx.commit()
g.tx = await g.s.begin()
from shared.infrastructure.fragments import fetch_fragment
frag_params = {"oob": "1"}
if ident["user_id"] is not None: