fix(drizzle): pass uuidMap in recursive insertArrays call#15787
Open
marcofadini wants to merge 1 commit intopayloadcms:mainfrom
Open
fix(drizzle): pass uuidMap in recursive insertArrays call#15787marcofadini wants to merge 1 commit intopayloadcms:mainfrom
marcofadini wants to merge 1 commit intopayloadcms:mainfrom
Conversation
The recursive call to insertArrays for sub-arrays (depth 3+) does not pass the uuidMap parameter. This causes junction table inserts for hasMany select/relationship fields nested inside blocks -> arrays -> sub-arrays to receive raw _uuid hex strings instead of database- generated UUIDs as parent_id, resulting in: invalid input syntax for type uuid: "69a16a831deaff58ca6ac371" This only affects versioned collections with hasMany fields at nesting depth >= 3, because the version insertion path goes through insertArrays where the mapping is needed for junction table foreign keys. The fix passes the shared uuidMap through the recursive call so all nesting levels share the same _uuid -> id mapping.
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.
What does this PR do?
Passes the
uuidMapparameter through the recursiveinsertArrayscall for sub-arrays, fixing a bug wherehasManyselect/relationship fields nested 3+ levels deep in versioned collections fail to save.Describe the Bug
When saving a document with a
hasMany: trueselect (or relationship) field nested 3+ levels deep (blocks -> array -> sub-array) in a versioned collection, PostgreSQL rejects the insert:insertArraysbuilds auuidMapthat maps_uuidhex strings to database-generatedidvalues. This map is needed so that junction table rows (forhasManyfields) receive the correct database UUID asparent_id. However, the recursive call for sub-arrays at line ~117 does not passuuidMap, so at depth 3+:_uuidhex string instead of a proper UUIDparent_idcolumn expects UUID typeThe Fix
One-line change — pass
uuidMapto the recursive call:await insertArrays({ adapter, arrays: row.arrays, db, parentRows: insertedRows, + uuidMap, })How to reproduce
versions: { drafts: true })hasMany: trueselect fieldExample schema that triggers this:
Related