Fix unique skip rewriting the existing job's kind under ExcludeKind - #1421
Merged
brandur merged 2 commits intoOct 4, 2026
Merged
Conversation
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>
brandur
approved these changes
Oct 2, 2026
brandur
left a comment
Contributor
There was a problem hiding this comment.
Thanks Jack! Looks great.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
ExcludeKind, jobs of different kinds can share a unique key. A skipped insert'sDO UPDATE SET kind = EXCLUDED.kindthen 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!