You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I came across this issue when using a relationship field while inside of a new document drawer. It happens because the document id passed in filterOptions({id}) is null when the field is inside of a new document drawer. Normally id is undefined when inside of a normal new document creation page. There are a few issues relating to this:
1. FilterOptionProps is incorrectly typed
FilterOptionsProps.id is currently typed as id: number | string. However the reality is that it can also be undefined (when inside of a normal document creation page) or null (when inside a document creation drawer): id?: number | string | null
2. Mismatch between the local API and the REST API. The REST API finds documents when it should find none in some situations
payload.find
✓ should find 1 doc (4 ms)
✓ should find 0 docs with id equals null (4 ms)
✓ should find 0 docs with id equals undefined (3 ms)
✓ should find 0 docs with id in [] (4 ms)
✓ should find 0 docs with id in [null] (3 ms)
✓ should find 0 docs with id in [undefined] (4 ms)
✓ payload.find with id in [] (3 ms)
REST API
✓ should find 1 doc (9 ms)
✓ should find 0 docs with id equals null (11 ms)
-> ✕ should find 0 docs with {id: {equals: undefined}} (9 ms)
-> ✕ should find 0 docs with id in [] (8 ms)
-> ✕ should find 0 docs with id in [undefined] (9 ms)
✕ should find 0 docs with id in [null] (9 ms)
3. Payload throws an exception when the where query is {id: {in: [null]}}
payload.find
✓ should find 1 doc (4 ms)
✓ should find 0 docs with id equals null (4 ms)
✓ should find 0 docs with id equals undefined (3 ms)
✓ should find 0 docs with id in [] (4 ms)
✓ should find 0 docs with id in [null] (3 ms)
✓ should find 0 docs with id in [undefined] (4 ms)
✓ payload.find with id in [] (3 ms)
REST API
✓ should find 1 doc (9 ms)
✓ should find 0 docs with id equals null (11 ms)
✕ should find 0 docs with {id: {equals: undefined}} (9 ms)
✕ should find 0 docs with id in [] (8 ms)
✕ should find 0 docs with id in [undefined] (9 ms)
-> ✕ should find 0 docs with id in [null] (9 ms)
[20:20:37] ERROR (payload): CastError: Cast to ObjectId failed for value "" (type string) at path "_id" for model "posts"
at model.Query.exec (/Users/user/code/amboss/payload/node_modules/.pnpm/mongoose@6.12.3/node_modules/mongoose/lib/query.js:4921:21)
at Function.paginate (/Users/user/code/amboss/payload/node_modules/.pnpm/mongoose-paginate-v2@1.7.22/node_modules/mongoose-paginate-v2/dist/index.js:147:53)
at Object.find (/Users/user/code/amboss/payload/packages/db-mongodb/src/find.ts:84:30)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at async find (/Users/user/code/amboss/payload/packages/payload/src/collections/operations/find.ts:145:16)
at async findHandler (/Users/user/code/amboss/payload/packages/payload/src/collections/requestHandlers/find.ts:30:20)
4. The previous issue can cause the relationship field to error when used inside a new document drawer
Screen.Recording.2024-04-24.at.20.26.08.mov
To Reproduce
Check the tests in the reproduction links and also the screenrecording:
Screen.Recording.2024-04-24.at.20.26.08.mov
Payload Version
2.13.0
Adapters and Plugins
No response
The text was updated successfully, but these errors were encountered:
Link to reproduction
main...franciscolourenco:payload:reproduce-relationship-null
Describe the Bug
I came across this issue when using a relationship field while inside of a new document drawer. It happens because the document
id
passed infilterOptions({id})
isnull
when the field is inside of a new document drawer. Normallyid
isundefined
when inside of a normal new document creation page. There are a few issues relating to this:1. FilterOptionProps is incorrectly typed
FilterOptionsProps.id is currently typed as
id: number | string
. However the reality is that it can also beundefined
(when inside of a normal document creation page) ornull
(when inside a document creation drawer):id?: number | string | null
2. Mismatch between the local API and the REST API. The REST API finds documents when it should find none in some situations
3. Payload throws an exception when the where query is
{id: {in: [null]}}
4. The previous issue can cause the relationship field to error when used inside a new document drawer
Screen.Recording.2024-04-24.at.20.26.08.mov
To Reproduce
Check the tests in the reproduction links and also the screenrecording:
Screen.Recording.2024-04-24.at.20.26.08.mov
Payload Version
2.13.0
Adapters and Plugins
No response
The text was updated successfully, but these errors were encountered: