fix: block reordering leaves orphaned rows in _rels tables#16770
Open
deepshekhardas wants to merge 7 commits into
Open
fix: block reordering leaves orphaned rows in _rels tables#16770deepshekhardas wants to merge 7 commits into
deepshekhardas wants to merge 7 commits into
Conversation
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
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.
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
Type of change