Skip to content

fix: guard against NaN when searching versioned collections by ID#16451

Open
aayushbaluni wants to merge 1 commit intopayloadcms:mainfrom
aayushbaluni:fix/15648-search-nan-draft-id
Open

fix: guard against NaN when searching versioned collections by ID#16451
aayushbaluni wants to merge 1 commit intopayloadcms:mainfrom
aayushbaluni:fix/15648-search-nan-draft-id

Conversation

@aayushbaluni
Copy link
Copy Markdown

Description

When list search merges an id condition and drafts are enabled, appendVersionToQueryKey rewrites id to parent. For numeric collection IDs, sanitizeQueryValue coerced the search string with Number() without rejecting non-numeric input, producing NaN as a bound parameter against parent_id (integer). Postgres then failed with invalid input syntax for type integer: "NaN".

This change returns null from sanitizeQueryValue when the coerced relationship ID is NaN, so parseParams skips adding that constraint (same pattern as polymorphic relationship handling). Other searchable fields in the same OR continue to work.

Fixes #15648

Made with Cursor

When searching collections with drafts enabled, the search logic parses
the search term as a numeric ID for parent_id comparison. Non-numeric
search terms produced NaN, which caused 'invalid input syntax for type
integer' errors on Postgres.

Fixes payloadcms#15648
@aayushbaluni aayushbaluni force-pushed the fix/15648-search-nan-draft-id branch from 239bc6b to 0c6f960 Compare May 1, 2026 18:48
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.

Error when searching for ID and drafts enabled

1 participant