Skip to content

fix(ui)!: remove equality operators from hasMany relationship filters - #15423

Closed
nehaaprasad wants to merge 3 commits into
payloadcms:mainfrom
nehaaprasad:fix/blnk-scr-cert-equ-ins
Closed

nehaaprasad wants to merge 3 commits into
payloadcms:mainfrom
nehaaprasad:fix/blnk-scr-cert-equ-ins

Conversation

@nehaaprasad

@nehaaprasad nehaaprasad commented Jan 29, 2026 •

Copy link
Copy Markdown
Contributor

Removes equals and not_equals from Admin list filters for hasMany relationship and upload fields with a single target collection. These fields offer in, not_in, and exists. Single-value fields and polymorphic fields keep their current operators.

Adds migrateHasManyRelationshipFilters from payload/migrations and upgrade instructions for saved query presets and legacy collection preferences. The migration preserves selected IDs, preset access, ownership, and unrelated preferences, processes records in batches, and can be run again safely.

Breaking Changes

Users upgrading to Payload 4 with saved equality filters on these fields must migrate them before reopening or editing those filters:

-{ relatedPages: { equals: ['first-id', 'second-id'] } }
+{ relatedPages: { in: ['first-id', 'second-id'] } }

-{ relatedPages: { not_equals: ['first-id', 'second-id'] } }
+{ relatedPages: { not_in: ['first-id', 'second-id'] } }

Create a database migration and call await migrateHasManyRelationshipFilters({ payload, req }) from its up function. The 4.x migration guide includes a complete example. Conflicting equality and membership constraints require manual review; the helper throws rather than overwriting either constraint.

On MongoDB, array-valued equality previously compared the entire array. Membership filters match any selected ID (in) or exclude all selected IDs (not_in), so filters relying on exact array equality can return different results after migration. API equality operators remain supported.

The database fix for #15387 is already covered by #15766; this change targets the 4.x Admin UI and saved-filter migration.

@JarrodMFlesch

JarrodMFlesch commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

The crash reported in #15387 was fixed in #15766, released in 3.82.0, but I closed this PR too quickly.

The frontend change here is still valuable. Since array-valued equals/not_equals filters are converted to in/not_in at the database level, showing the matching operators in the Admin makes that behavior clearer. My earlier suggestion to remove equals/not_equals from the hasMany filter UI still makes sense; the database portion is already covered by #15766.

Thank you for contributing and for following up on my feedback.

@JarrodMFlesch JarrodMFlesch reopened this Oct 27, 2026
@JarrodMFlesch JarrodMFlesch changed the title fix(drizzle): use scalar for equals/not_equals on relationship filters fix(ui): remove equality operators from hasMany relationship filters Oct 27, 2026
@JarrodMFlesch JarrodMFlesch changed the title fix(ui): remove equality operators from hasMany relationship filters fix(ui)!: remove equality operators from hasMany relationship filters Oct 27, 2026
@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between cdb8ec4 and 654422f.

Files selected for processing: 15
  • docs/migration-guide/v4.mdx
  • packages/payload/src/database/migrations/hasManyRelationshipFilters/index.spec.ts
  • packages/payload/src/database/migrations/hasManyRelationshipFilters/index.ts
  • packages/payload/src/database/migrations/hasManyRelationshipFilters/migrateWhere.spec.ts
  • packages/payload/src/database/migrations/hasManyRelationshipFilters/migrateWhere.ts
  • packages/payload/src/exports/migrations.ts
  • packages/ui/src/elements/WhereBuilder/field-types.spec.ts
  • packages/ui/src/elements/WhereBuilder/field-types.tsx
  • packages/ui/src/elements/WhereBuilder/index.tsx
  • test/a11y/WCAG.e2e.spec.ts
  • test/fields/collections/Relationship/e2e.spec.ts
  • test/query-presets/collections/Posts/index.ts
  • test/query-presets/e2e.spec.ts
  • test/query-presets/payload-types.ts
  • test/query-presets/relationshipFilters.int.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

The Admin filter builder now uses membership operators for single-target has-many relationship and upload fields. A migration helper converts matching saved preset and preference filters from equality operators to membership operators.

Changes: Has-many filter migration

Layer / File(s) Summary
WhereBuilder operator support
packages/ui/src/elements/WhereBuilder/*, test/fields/collections/Relationship/e2e.spec.ts, test/a11y/WCAG.e2e.spec.ts
The WhereBuilder uses in, not_in, and exists for single-target has-many relationship and upload fields. The default operator comes from the valid operator list. Tests cover operator choices and keyboard interaction.
Saved-filter condition conversion
packages/payload/src/database/migrations/hasManyRelationshipFilters/migrateWhere.*
migrateWhere recursively changes eligible equals and not_equals constraints to in and not_in. Tests cover nested conditions, field types, preserved values, and conflicting constraints.
Saved preset and preference migration
packages/payload/src/database/migrations/hasManyRelationshipFilters/index.*, packages/payload/src/exports/migrations.ts, test/query-presets/*, docs/migration-guide/v4.mdx
migrateHasManyRelationshipFilters scans configured presets and preferences in batches, updates changed filters, and returns the update count. Tests cover metadata preservation, query results, reruns, and editing migrated filters. The migration guide documents how to run the helper and its behavior.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant MigrationScript
  participant migrateHasManyRelationshipFilters
  participant PayloadDatabaseAdapter
  participant migrateWhere
  MigrationScript->>migrateHasManyRelationshipFilters: pass payload and request
  migrateHasManyRelationshipFilters->>PayloadDatabaseAdapter: fetch preset and preference records
  migrateHasManyRelationshipFilters->>migrateWhere: convert each saved where filter
  migrateWhere-->>migrateHasManyRelationshipFilters: return converted filter
  migrateHasManyRelationshipFilters->>PayloadDatabaseAdapter: update changed records
  migrateHasManyRelationshipFilters-->>MigrationScript: return updated-record count
Loading
Merge Risk: Minimal · up to 65442

The filter UI and saved-filter migration are mergeable after normal checks; no actionable issue remains identified.

Security architecture risk: Low · up to 65442

The change is limited to Admin filtering and an explicitly invoked migration. The inspected list-loading path retains separate authorization checks, and the migration preserves ownership and access settings. Remaining risks concern changed filter results, concurrent edits, and backup-dependent rollback rather than a demonstrated authorization bypass.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • observed — The trusted migration can rewrite eligible saved filters across all users in both configured internal collections. Its writes target saved-filter records, not referenced content documents, and are not restricted to the invoking user.

Security Findings and Attack Paths

  • inferred — No attacker-reachable invocation of the new privileged helper was established. Inspected callers use migration execution or tests. The package export requires trusted server-side handling; downstream custom handlers were not assessed.

Trust Boundaries and Controls

  • observed — In the inspected Admin list path, preset retrieval enforces access independently of the saved where clause. The ordinary target collection query also uses overrideAccess:false and combines the saved selection with configured base filters. Broader membership results therefore do not themselves demonstrate an authorization bypass.

Resilience and Maintainability Implications

  • inferred — Failure containment depends on transaction-capable execution with the supplied migration request. ID-only updates provide no explicit stale-write predicate, and offset pagination provides no independent stable snapshot. Concurrent saved-filter changes could therefore be overwritten or missed under insufficient isolation; cross-adapter behavior was not established.

Hardening Proposals

  • proposed — Use a controlled migration window with saved-filter writes paused, verify transaction support for the configured adapter, and retain a tested backup until filter-result validation is complete. If online execution is required, consider conflict detection and stable pagination.
Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title names the main change: removing the equality operators from hasMany relationship filters in the Admin UI. The changeset matches this, including the field-types, WhereBuilder, and migration c…
Description check Passed The description states that equals and not_equals are removed from Admin list filters for hasMany relationship and upload fields with one target collection. It also describes the new migrateHasManyRel…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within survi…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: removing the equality operators from hasMany relationship filters in the Admin UI. The changeset matches this, including the field-types, WhereBuilder, and migration changes. The title is concise and specific, and the 'fix(ui)!' prefix flags a breaking change.

Full details: Description check

Explanation

The description states that equals and not_equals are removed from Admin list filters for hasMany relationship and upload fields with one target collection. It also describes the new migrateHasManyRelationshipFilters helper, the upgrade steps, and the breaking-change impact. All of this matches the changeset.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 14 files. (1 skipped: 1 unsupported.)

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@JarrodMFlesch

Copy link
Copy Markdown
Contributor

I explored narrowing this to 4.x and providing a migration for existing saved filters, but that uncovered a difference between the adapters.

MongoDB supports exact-array matching with equals / not_equals, while Postgres currently treats those array-valued filters as in / not_in. Removing the equality operators from the Admin would take away functionality MongoDB users have today, and migrating their saved filters could change which documents match.

I’m going to pause this for now until we settle what these operators should mean across adapters and how to preserve existing functionality. The original Postgres crash is already fixed by #15766, so we have room to work through that separately.

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.

3 participants