Fix task cancel: filter pending events by dedupe_key

SimEvent.payload is a generic SQLAlchemy JSON column, so .astext
(JSONB-only) raises AttributeError at runtime on every backend.
Filter on dedupe_key with the existing task:{tid}:* scheme, which
matches how core/eta.py queries the same events.
This commit is contained in:
Dan Austin 2026-04-13 12:47:30 +01:00
parent bfb0c88062
commit 3379ca0b7f

View file

@ -702,13 +702,14 @@ def task_cancel(
# Set status to cancelled
task.status = TaskStatus.CANCELLED
# Drop pending events for this task
# Drop pending events for this task. Filter on dedupe_key (task:{tid}:*)
# rather than payload — payload is generic JSON and `.astext` is JSONB-only.
pending_events = (
db.query(SimEvent)
.filter(
SimEvent.company_id == sim_state.company_id,
SimEvent.consumed == False,
SimEvent.payload["task_id"].astext == str(tid),
SimEvent.dedupe_key.like(f"task:{tid}:%"),
)
.all()
)