Skip to content

fix(drizzle): pass uuidMap in recursive insertArrays call#15787

Open
marcofadini wants to merge 1 commit intopayloadcms:mainfrom
marcofadini:fix/insert-arrays-pass-uuidmap-recursive
Open

fix(drizzle): pass uuidMap in recursive insertArrays call#15787
marcofadini wants to merge 1 commit intopayloadcms:mainfrom
marcofadini:fix/insert-arrays-pass-uuidmap-recursive

Conversation

@marcofadini
Copy link

What does this PR do?

Passes the uuidMap parameter through the recursive insertArrays call for sub-arrays, fixing a bug where hasMany select/relationship fields nested 3+ levels deep in versioned collections fail to save.

Describe the Bug

When saving a document with a hasMany: true select (or relationship) field nested 3+ levels deep (blocks -> array -> sub-array) in a versioned collection, PostgreSQL rejects the insert:

invalid input syntax for type uuid: "69a16a831deaff58ca6ac371"

insertArrays builds a uuidMap that maps _uuid hex strings to database-generated id values. This map is needed so that junction table rows (for hasMany fields) receive the correct database UUID as parent_id. However, the recursive call for sub-arrays at line ~117 does not pass uuidMap, so at depth 3+:

  • The junction table INSERT receives a raw 24-char _uuid hex string instead of a proper UUID
  • PostgreSQL rejects it because the parent_id column expects UUID type

The Fix

One-line change — pass uuidMap to the recursive call:

       await insertArrays({
         adapter,
         arrays: row.arrays,
         db,
         parentRows: insertedRows,
+        uuidMap,
       })

How to reproduce

  1. Create a versioned collection (versions: { drafts: true })
  2. Add a blocks field containing an array, containing a sub-array
  3. In the sub-array, add a hasMany: true select field
  4. Create a document, populate all levels including the hasMany field
  5. Save -> error

Example schema that triggers this:

Page (versioned, drafts: true)
  -> layout (blocks)
    -> HeroCarousel (block)
      -> slides (array)
        -> actions (array)            <-- depth 3
          -> rel (hasMany select)     <-- junction table INSERT fails

Related

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant