Skip to content

fix(drizzle, db-mongodb): handle ['null'] array when filtering hasMany relationship field by None#16293

Open
lcnogueira wants to merge 5 commits intopayloadcms:mainfrom
lcnogueira:fix/null-hasMany-relationship-filter
Open

fix(drizzle, db-mongodb): handle ['null'] array when filtering hasMany relationship field by None#16293
lcnogueira wants to merge 5 commits intopayloadcms:mainfrom
lcnogueira:fix/null-hasMany-relationship-filter

Conversation

@lcnogueira
Copy link
Copy Markdown
Contributor

@lcnogueira lcnogueira commented Apr 16, 2026

What?

When filtering a hasMany relationship field by None in the Payload admin panel list view, no results are returned — even when documents with no related entries exist.

Why?

The issue exists in both packages/drizzle/src/queries/sanitizeQueryValue.ts and packages/db-mongodb/src/queries/sanitizeQueryValue.ts, inside the relationship/upload type block.

When the admin UI sends a "None" filter for a hasMany relationship field, the value arrives as ['null'] — an array containing the string 'null'. The current null check in both adapters only handles the plain string form:

if (val === 'null') {
  formattedValue = null
}

Since ['null'] !== 'null', the check is bypassed. In the drizzle adapter, the ['null'] value then reaches the array-handling branch which converts operator: 'equals' to operator: 'in' with value: ['null'], generating:

WHERE types_id IN ('null')

In the MongoDB adapter, the unconverted ['null'] value causes a query error, returning { errors: [...] } instead of results.

Both cases result in the filter producing no valid output.

How?

Extended the null check in both adapters to also handle the ['null'] array form that hasMany relationship fields produce:

// before
if (val === 'null') {
  formattedValue = null
}

// after
if (val === 'null' || (Array.isArray(val) && val.length === 1 && val[0] === 'null')) {
  formattedValue = null
}

Fixes #16292

@lcnogueira lcnogueira changed the title fix(db-postgres): handle ['null'] array when filtering hasMany relationship field by None fix(db-postgres, db-mongodb): handle ['null'] array when filtering hasMany relationship field by None Apr 16, 2026
@lcnogueira lcnogueira marked this pull request as ready for review April 16, 2026 11:51
@lcnogueira lcnogueira changed the title fix(db-postgres, db-mongodb): handle ['null'] array when filtering hasMany relationship field by None fix(drizzle, db-mongodb): handle ['null'] array when filtering hasMany relationship field by None Apr 16, 2026
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.

Filtering a hasMany relationship field by "None" returns a blank screen instead of the No results message

1 participant