feat(workflow): start(first, key=) tells a resent event apart from a clash on another unique column
Merged
MA
8d ago+554+554+012345678901234567890123456789-22-22-01234567890123456789
Requested by Masen · project thread
Type of change
- New feature (non-breaking change which adds functionality)
- This change requires a documentation update (included)
What
Workflow.start inserts with ON CONFLICT DO NOTHING and no target, so a clash on any unique column returns False. A webhook receiver (the Workflows-in-the-Builder trigger route) has to answer "duplicate" for a resend and something else for a real conflict, and today it can't tell them apart.
await row.start(first, key=Model.column)inserts withON CONFLICT (column) DO NOTHING.Falsethen means exactly "a run with this key already exists".- A clash on any other unique constraint raises the new
RunConflict, whose.constraintis the name the driver reported (psycopgdiag, or the chained asyncpg error), orNone. key=must name a column unique on its own: a single-column primary key,unique=True, a single-columnUniqueConstraint, or a non-partial unique index. Anything else raisesTypeError/ValueErrorbefore the insert, since Postgres would reject theON CONFLICTtarget anyway (or silently need aWHEREfor a partial index).- Without
key=, behaviour is unchanged.fan_outchildren are untouched.
Notes for review
- The ticket asked for SQLite tests too, but the engine is Postgres-only (
pg_insert), so the start tests run underREFLEX_TEST_POSTGRESliketest_claim.py/test_runner.py. Thekey_columnrefusal tests need no database and run everywhere. - Fixes a bug from the prototype: a partial unique index made
key_columnraiseTypeError: Boolean value of this clause is not definedinstead of refusing it. - Docs: a "Key a run on an outside event" section in
docs/workflows/runs.md, andstart(key=)plusRunConflictin the reference.
Tests
uv run pytest tests/units/reflex_workflowagainst Postgres 16: 1069 passed.- ruff, ruff format, pyright, pre-commit clean on the touched files.
Linear: ENG-13935
Generated by Claude Code