Repository navigation
entc/gen: setting a field after clearing it undoes the clear - #13
Merged
Merged
Conversation
ClearX() then SetX() left the mutation with the field both set and cleared: X() answered with the value and XCleared() with true. An update emitted both, `SET x = NULL, x = ?`. SQLite, MySQL and MariaDB let the later assignment win, which happens to be the value; PostgreSQL refuses the statement with "multiple assignments to same column". A hook saw both states at once. Every other pair already lets the later call win: Clear drops a value that was set, Set drops what was added or appended. The update builder's setter for a numeric field even calls Reset first, which drops the clear -- put there in 2019 to drop the Add, and doing this as a side effect. SetX now drops the clear of an optional field, so the rule holds for every field and for a mutation set directly, as a hook does. Upstream has the same code. Nothing about it was reported there. Tested in ClearFields on every engine: after ClearUser().SetUser(v) the mutation is not cleared, and the row holds v. It fails on PostgreSQL and on the mutation's state without this change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lesomnus
force-pushed
the
clear-then-set
branch
from
October 18, 2026 08:22
88256d3 to
d687890
Compare
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.
ClearX()followed bySetX()left the mutation with the field both set and cleared:X()answered with the value, andXCleared()answeredtrue. An update then emitted both assignments,SET x = NULL, x = ?.multiple assignments to same columnEvery other pair of calls already lets the later call win:
ClearXdrops a value that was set.SetXdrops what was added or appended.ResetXfirst, which also drops the clear. That call was added in 2019 to drop the Add, not for this case.This change makes
SetXdrop the clear of an optional field. The rule then holds for every field, including when a hook sets the mutation directly. The template change is one line; the rest of the diff is regeneratedmutation.gofiles.Upstream has the same code, and nothing about it had been reported there. UPSTREAM.md gains a Set after clear row, which says to drop it once upstream has the fix.
Tests
ClearFieldsinentc/integrationgains a "set after clear" case. AfterClearUser().SetUser(v), the mutation is not cleared, and the row holdsv.examplestests pass;entc/integrationmatrix passes with-race -count=2on SQLite, MySQL 8.0 and 8.4, MariaDB 10.11 and 11.4, and PostgreSQL 14 and 17;.github/lint.shpasses.🤖 Generated with Claude Code