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:
@@ -125,7 +125,10 @@ def register() -> Blueprint:
|
|||||||
# Load entry DTO for the widget template
|
# Load entry DTO for the widget template
|
||||||
entry = await services.calendar.entry_by_id(g.s, entry_id)
|
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
|
from shared.infrastructure.fragments import fetch_fragment
|
||||||
frag_params = {"oob": "1"}
|
frag_params = {"oob": "1"}
|
||||||
if ident["user_id"] is not None:
|
if ident["user_id"] is not None:
|
||||||
|
|||||||
@@ -8,9 +8,6 @@ from quart import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
from sqlalchemy import update, func as sa_func
|
|
||||||
|
|
||||||
from models.calendars import CalendarEntry
|
|
||||||
|
|
||||||
|
|
||||||
from .services.entries import (
|
from .services.entries import (
|
||||||
@@ -206,18 +203,9 @@ def register():
|
|||||||
entry.ticket_price = ticket_price
|
entry.ticket_price = ticket_price
|
||||||
entry.ticket_count = ticket_count
|
entry.ticket_count = ticket_count
|
||||||
|
|
||||||
# Count pending calendar entries from local session (sees the just-added entry)
|
# Commit so cross-service calls see the new entry
|
||||||
user_id = getattr(g, "user", None) and g.user.id
|
await g.tx.commit()
|
||||||
cal_filters = [
|
g.tx = await g.s.begin()
|
||||||
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
|
|
||||||
|
|
||||||
from shared.infrastructure.cart_identity import current_cart_identity
|
from shared.infrastructure.cart_identity import current_cart_identity
|
||||||
from shared.infrastructure.fragments import fetch_fragment
|
from shared.infrastructure.fragments import fetch_fragment
|
||||||
|
|||||||
@@ -106,7 +106,10 @@ def register() -> Blueprint:
|
|||||||
# Load entry DTO for the widget template
|
# Load entry DTO for the widget template
|
||||||
entry = await services.calendar.entry_by_id(g.s, entry_id)
|
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
|
from shared.infrastructure.fragments import fetch_fragment
|
||||||
frag_params = {"oob": "1"}
|
frag_params = {"oob": "1"}
|
||||||
if ident["user_id"] is not None:
|
if ident["user_id"] is not None:
|
||||||
|
|||||||
Reference in New Issue
Block a user