fix(orm): evaluate $onUpdate lazily in buildUpdateSet across dialects#5851
Open
chatman-media wants to merge 1 commit into
Open
fix(orm): evaluate $onUpdate lazily in buildUpdateSet across dialects#5851chatman-media wants to merge 1 commit into
chatman-media wants to merge 1 commit into
Conversation
buildUpdateSet computed `col.onUpdateFn?.()` eagerly for every column and only used the result when the column was absent from `set` (via `??`). Any $onUpdate callback with side effects (throw, logging, reading external state) therefore ran on every UPDATE, even when the column value was explicitly provided. This regressed the lazy 0.44.6 behavior. Only invoke the callback when the column is absent from `set`. Applied to the pg, mysql, sqlite, singlestore and gel dialects. Closes drizzle-team#5780
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.
Closes #5780.
buildUpdateSetcomputedcol.onUpdateFn?.()eagerly for every column, then only used the result when the column was absent fromset(set[colName] ?? …). So any$onUpdatecallback with side effects —throw, logging, reading external state — ran on everyUPDATE, even when the column value was explicitly provided and would win via??. This is a regression from the lazy0.44.6behavior.Fix: only evaluate the callback when the column is absent from
set(set[colName] == null, matching the existing??semantics). The value line is unchanged. Applied to all five dialects that share this code path: pg, mysql, sqlite, singlestore, gel.Test: added a DB-less unit test (
tests/on-update-set.test.ts) — a throwing$onUpdatewith an explicit value must not throw, and an absent column must still invoke the callback.🤖 Generated with Claude Code