payloadcms / payload

The best way to build a modern backend + admin UI. No black magic, all TypeScript, and fully open-source, Payload is both an app framework and a headless CMS.
https://payloadcms.com
MIT License
21.04k stars 1.27k forks source link

Exception when filtering by polymorphic relationship field, and collection has drafts enabled #6880

Open franciscolourenco opened 1 week ago

franciscolourenco commented 1 week ago

Link to reproduction

https://github.com/payloadcms/payload/compare/franciscolourenco:reproduce-filter-relationship-versions

Describe the Bug

In the list view, when filtering document by a polymorphic relationship field, an exception is thrown. This only seems to happen when the filtered collection has drafts enabled.

image
[20:25:38] ERROR (payload): QueryError: The following path cannot be queried: version
    at validateQueryPaths ((...)/payload/packages/payload/src/database/queryValidation/validateQueryPaths.ts:91:13)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async find ((...)/payload/packages/payload/src/collections/operations/find.ts:119:7)
    at async findHandler ((...)/payload/packages/payload/src/collections/requestHandlers/find.ts:30:20)

To Reproduce

  1. Create a collection with drafts enabled.
  2. Add a polymorphic relationship field.
  3. Use the Admin UI to filter the collection documents using the relationship field

Payload Version

2.22.0

Adapters and Plugins

No response