payloadcms / payload

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
https://payloadcms.com
MIT License
24.93k stars 1.59k forks source link

Multiple query filters on array fields produce "Alias "x" is already used in this query" error #8517

Closed dsod closed 1 week ago

dsod commented 1 month ago

Link to reproduction

https://github.com/dsod/payload-nested-docs-alias-bug

Environment Info

Payload: `3.0.0-beta.109`
NodeJs: 20x
Postgres: 15x

Describe the Bug

When you add multiple query filters onto a array field, for example through access control functions and filterOptions using a Postgres server, Drizzle will throw an error like Error: Alias "" is already used in this query.

The reproduction repository I created is using the Nested docs core plugin to reproduce the error. The plugin adds filterOptions onto the parent field, this in combination with my access control function on the users collection is enough to trigger the error.

Reproduction Steps

When the parent dropdown is opened from the UI and the filterOptions is triggered, which filters on the breadcrumbs field in addition to my access control query, the error is triggered.

More details can be found in the repo readme.

Adapters and Plugins

db-postgres, nested-docs-plugin

r1tsuu commented 1 week ago

Hey @dsod, thank you for you issue! Fixed in https://github.com/payloadcms/payload/pull/8823

github-actions[bot] commented 1 week ago

🚀 This is included in version v3.0.0-beta.118

github-actions[bot] commented 1 week ago

This issue has been automatically locked. Please open a new issue if this issue persists with any additional detail.