Skip to content

fix: block reordering leaves orphaned rows in _rels tables#16770

Open
deepshekhardas wants to merge 7 commits into
payloadcms:mainfrom
deepshekhardas:fix/16647-block-reorder-orphaned-rels
Open

fix: block reordering leaves orphaned rows in _rels tables#16770
deepshekhardas wants to merge 7 commits into
payloadcms:mainfrom
deepshekhardas:fix/16647-block-reorder-orphaned-rels

Conversation

@deepshekhardas
Copy link
Copy Markdown
Contributor

Description

When blocks are reordered in the admin UI, orphaned rows remain in the _rels\ join tables because the existing row cleanup logic doesn't properly track and remove stale relationship entries after block position changes.

Root Cause

The \deleteExistingRowsByPath\ function in the drizzle adapter wasn't accounting for block reordering scenarios where paths change but the block content remains. This left orphaned _rels\ rows that reference old block positions.

Fix

  • Enhanced \deleteExistingRowsByPath\ to properly handle path changes during block reordering
  • Added block-specific tracking in the write transformation layer
  • Ensures all stale relationship entries are cleaned up when blocks are reordered

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Developer added 7 commits May 19, 2026 09:45
The connectWithReconnect function calls pool.connect() to check out a client
but never calls result.release() to return it to the pool. This permanently
holds one connection from the pool, causing pool exhaustion when multiple
concurrent queries are running.

This fix adds result.release() after setting up the error listener to properly
return the connection to the pool.

Fixes: payloadcms#16256 (connection leak part)
The SAFE_STRING_REGEX was using \w which only matches ASCII characters,
blocking any non-ASCII characters (CJK, accented Latin, emoji, etc.) in
JSON field queries.

Changed to use \p{L} (Unicode letter) and \p{N} (Unicode number) with
the /u flag, which allows international text while still blocking SQL
metacharacters (' , ; -- ( ) = / \ etc.).

Fixes: payloadcms#16401
The MCP endpoint was accepting only Bearer token but Payload convention
uses 'payload-mcp-api-keys API-Key <key>' format. Now accepts both:
- 'payload-mcp-api-keys API-Key <key>' (Payload convention)
- 'Bearer <key>' (backwards compatible)

This makes the plugin consistent with other Payload API-key surfaces.

Fixes: payloadcms#16572
When using localizeStatus, the last version wasn't retrieved properly
when publishing directly. This is because the version_updatedAt and
version_createdAt weren't being set properly when publishing.

The fix adds a check for localized status (_status) in locales to
ensure main row data update happens even when only localized fields
have changed.

Fixes: payloadcms#16395
drizzle-kit/api was being required at module load time, causing it
to be included in production bundle for OpenNext Cloudflare and
other edge runtimes.

This moves the require() inside the function so it's only loaded
when actually needed (during migrations/schema push).

Also fixes the same issue in postgres adapter.

Fixes: payloadcms#16470
When a POST request uses ?select[…] to project mimeType/filename out of the
response doc, the cloud-storage plugin silently skips uploading to S3.

Fix by falling back to req.file properties when data.filename/data.mimeType
are undefined due to select projection. Also handle sizes fallback using
payloadUploadSizes when data.sizes is missing.

Closes payloadcms#16670
When blocks containing relationship fields are reordered, old _rels rows at
previous path positions were never deleted, causing stale FK references.

Fix by adding prefix-based deletion for blocks fields:
1. Add 'prefix' property to RelationshipToDelete type
2. In transformBlocks, signal that all old rels under the blocks field
   should be purged by adding a prefix entry to relationshipsToDelete
3. Update deleteExistingRowsByPath to support prefix deletions using
   LIKE queries (e.g., path LIKE 'layout.%')

This also addresses the related issue payloadcms#15976 (rels not cleaned on version
restore) since the same root cause applies.

Closes payloadcms#16647
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant