Repository navigation
fix(qc): don't apply the nested upsert where filter to the parent update - #5854
Open
samuelmbabhazi wants to merge 1 commit into
Open
samuelmbabhazi wants to merge 1 commit into
samuelmbabhazi wants to merge 1 commit into
Conversation
For a to-one relation inlined on the parent, the create branch of a nested upsert connects the newly created child by updating the foreign key on the parent. That update node received the upsert where filter, which belongs to the child model, so the rendered SQL referenced a child column inside the update on the parent table and the query failed with "The column X does not exist in the current database". The parent rows are already pinned by the injected selectors, and the equivalent connect step in nested connect and connectOrCreate passes an empty filter, so do the same here. Fixes prisma/orm#29744
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
Summary by CodeRabbit
WalkthroughThe nested upsert builder now moves the consumed 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This branch has not been deployed
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.
Problem
Reported in prisma/orm#29744.
A nested upsert on a to-one relation that is inlined on the parent fails when the optional
wherefilter is provided and the create branch is taken. The generated SQL for the step that connects the newly created child references a child column inside the UPDATE on the parent table:The database rejects this with
The column User.email does not exist in the current database, a cross table reference without a join. The bug only triggers when thewhereargument is passed, which is optional on to-one upserts. Without it the filter is empty and the query is valid, which is why this went mostly unnoticed.Root cause
In
nested_upsert, the update node that writes the foreign key on the parent receives the upsertwherefilter. That filter belongs to the child model, its only role is to select which child to read and update. The equivalent connect step innested_connect,nested_connect_or_createandnested_createpassesFilter::empty()to the same placeholder, since the parent rows are already pinned by the selectors injected through the graph edge.Fix
Pass
Filter::empty()for the parent update, matching the sibling builders. A now redundant clone of the filter is also removed since the filter is moved at its last remaining use.Tests
update-nested-upsert.jsoncovering the failing shape, a to-one relation inlined on the parent with awherefilter. Before the fix the snapshot contains the invalid cross table condition shown above, after the fix the parent update is filtered by the selectors only. No other snapshot changed.cargo test -p query-core -p query-compiler -p sql-query-builderpasses.cargo fmt --checkandcargo clippy -p query-core -p query-compiler --all-targetswith warnings as errors are clean.