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
There's no other issue that already describes my problem.
Describe the Bug
If you call directus.items('my_collection').readOne(id) and id happens to be an empty string, the request will return an array of objects matching directus.items('my_collection').readMany().
Either the typing of readOne is not correct or calling readOne with an empty string should fail.
If you ask me, I'd like readOne to always behave the same and not fall back to readMany behavior. But that's a breaking change and would require a guard in readOne which is a high cost just for the sake of consistency. If we were to rely on typescript we could extend IItems to have the appropriate return types for readOne.
At the very least, I propose to create a PR for the docs at https://docs.directus.io/reference/sdk/#read-single-item. This behavior should be documented somewhere. But I'm waiting for your judgment on how readOne should behave.
To Reproduce
Use the directus sdk and call directus.items('my_collection').readOne(''). The http request will go to <directus-location>/items/rh_members/ and return an array.
Errors Shown
No response
What version of Directus are you using?
9.6.0
What version of Node.js are you using?
16.14.0
What database are you using?
Postgres 14
What browser are you using?
chrome
What operating system are you using?
macos
How are you deploying Directus?
docker
The text was updated successfully, but these errors were encountered:
Since you are passing an empty string, it is indeed doing /items/my_collection/ + '', which became the readMany endpoint /items/my_collection in the end. Thanks for bringing this to our attention! Just to answer your question, this is most definitely not an intended behaviour.
Preflight Checklist
Describe the Bug
If you call
directus.items('my_collection').readOne(id)
andid
happens to be an empty string, the request will return an array of objects matchingdirectus.items('my_collection').readMany()
.Either the typing of
readOne
is not correct or callingreadOne
with an empty string should fail.If you ask me, I'd like
readOne
to always behave the same and not fall back toreadMany
behavior. But that's a breaking change and would require a guard inreadOne
which is a high cost just for the sake of consistency. If we were to rely on typescript we could extendIItems
to have the appropriate return types forreadOne
.At the very least, I propose to create a PR for the docs at https://docs.directus.io/reference/sdk/#read-single-item. This behavior should be documented somewhere. But I'm waiting for your judgment on how
readOne
should behave.To Reproduce
Use the directus sdk and call
directus.items('my_collection').readOne('')
. The http request will go to<directus-location>/items/rh_members/
and return an array.Errors Shown
No response
What version of Directus are you using?
9.6.0
What version of Node.js are you using?
16.14.0
What database are you using?
Postgres 14
What browser are you using?
chrome
What operating system are you using?
macos
How are you deploying Directus?
docker
The text was updated successfully, but these errors were encountered: