Repository navigation
Conversation
Model.bulkCreate assigns the rows returned by INSERT ... ON CONFLICT DO UPDATE ... RETURNING to its instances by position, which assumes that the rows come back in the order of the VALUES list. CockroachDB does not guarantee this: it plans the conflict check as a left outer join of the VALUES against the conflict index, and both the lookup join and the hash join can return rows that matched an existing row (and are updated) before rows that did not (and are inserted). With updateOnDuplicate, instances could be populated with the primary key and values of a different row. This happens for any conflict target, including the primary key, not only for partial indexes with conflictWhere. Wrap bulkInsert so that, when updateOnDuplicate is used, the returned rows are matched back to the input records by the values of the conflict target columns (upsertKeys). Records with a NULL or DEFAULT conflict key are always inserted, so they are matched to the remaining rows in order. If the rows cannot be matched unambiguously, they are returned unchanged. Plain INSERT, UPSERT and ON CONFLICT DO NOTHING without conflicts return rows in input order today, so bulkCreate without updateOnDuplicate is not changed. Stop ignoring the Sequelize "should upsert existing memberships" test, which now passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Model.bulkCreate assigns the rows returned by
INSERT ... ON CONFLICT DO UPDATE ... RETURNING to its instances by
position, which assumes that the rows come back in the order of the
VALUES list. CockroachDB does not guarantee this: it plans the conflict
check as a left outer join of the VALUES against the conflict index,
and both the lookup join and the hash join can return rows that matched
an existing row (and are updated) before rows that did not (and are
inserted). With updateOnDuplicate, instances could be populated with
the primary key and values of a different row. This happens for any
conflict target, including the primary key, not only for partial
indexes with conflictWhere.
Wrap bulkInsert so that, when updateOnDuplicate is used, the returned
rows are matched back to the input records by the values of the
conflict target columns (upsertKeys). Records with a NULL or DEFAULT
conflict key are always inserted, so they are matched to the remaining
rows in order. If the rows cannot be matched unambiguously, they are
returned unchanged.
Plain INSERT, UPSERT and ON CONFLICT DO NOTHING without conflicts
return rows in input order today, so bulkCreate without
updateOnDuplicate is not changed.
Stop ignoring the Sequelize "should upsert existing memberships" test,
which now passes.
🤖 Generated with Claude Code