Skip to content

Fix unique skip rewriting the existing job's kind under ExcludeKind - #1421

Merged
brandur merged 2 commits into
riverqueue:masterfrom
JackDanger:fix/unique-skip-rewrites-kind
Oct 4, 2026
Merged

brandur merged 2 commits into
riverqueue:masterfrom
JackDanger:fix/unique-skip-rewrites-kind

Conversation

@JackDanger

Copy link
Copy Markdown
Contributor

With ExcludeKind, jobs of different kinds can share a unique key. A skipped insert's DO UPDATE SET kind = EXCLUDED.kind then rewrote the existing job to the new kind.

This sets the kind to the existing row's own instead, and adds a driver test that fails without the change.

The bug dates back to ExcludeKind's introduction (#590), not #1404.

Happy to adjust or close if you'd prefer a different approach. Thanks!

The unique insert upsert returns the conflicting row with
`DO UPDATE SET kind = EXCLUDED.kind`. With `UniqueOpts.ExcludeKind`, jobs
of different kinds can share a unique key, so a skipped insert of kind B
rewrote the existing kind A job to kind B. That job was then worked by B's
worker with A's args, or failed as an unknown kind.

Set the kind to the existing row's own instead, which keeps the update
(and the returned row) but makes it a no-op. Changed in `JobInsertFastMany`
for Postgres and SQLite, and in SQLite's unused `JobInsertFast` for
consistency.

Signed-off-by: Jack Danger <github@jackcanty.com>
Copilot AI balanced review requested due to automatic review settings October 2, 2026 22:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@brandur brandur left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Jack! Looks great.

@brandur
brandur merged commit cf809b4 into riverqueue:master Oct 4, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants