convex-test fails for nested optional properties used in index
Hi, I am reporting a bug that happens in convex-test, when you use an optional property in an index.
In this example, you see that
add_info
is an optional property (by way of being excluded in one of the types within a discriminated union type).
1. There is no type error
2. The test fails in convex-test
3. The test passes against the live convex server
I've also create a full reproduction with different scenarios (refer to commit history) here.
- https://github.com/conradkoh/convex-test-index-bug-repo/commits/master/
Thanks in advance.
Schema
Query Code
Test
Error
12 Replies
also import to note in the repro that generally, there are issues detecting the generated folder when using pnpm, but in yarn it works fine.
@Michal Srb I'm not sure if this is the correct fix, but I created a PR to the main repo here:
https://github.com/get-convex/convex-test/pull/10
GitHub
ensure that null values are not simple objects by conradkoh · Pull ...
Fix crashes in test when using nested optional properties in an index
There is no type error
The test fails in convex-test
The test passes against the live convex server
Schema
export default def...
the issue I think is that
typeof null
is "object"
, and this was a case not considered in the implementation of the function.
also, supplementing the other lines of the stack trace for info
thanks for the bug report! I don't see any nulls in your example; if a field is missing it's considered undefined for the purpose of index equality
but you're probably right about the prototype thing. I don't know off the top of my head how prototype works for null and undefined 🙂
@lee from the little I know about what I can see, I believe there is a false assumption somewhere that an the value of the index (split by
.
) will always result in a value that can be evaluated by Object.getPrototypeOf
.
unfortunately, when you call Object.getPrototypeOf(null)
or Object.getPrototypeOf(undefined)
, it will throw an exception rather than return null
.
this results in the error TypeError: Cannot convert undefined or null to object
yep makes sense. Good find
I notice that using array[0] without the proper check throws errors in tests but not bundled code sent to convex.
obviously you should just do .first() or do result && await. but to make both happy a null check for like result[0] works.
That's a poor example but i know its also not respecting working code in my event system, i have actions deep not getting triggered, and going through a new debug process for just tests is not fun. SO its either a error from having too many nested functions or something like that above.
also looks like my query works even if i use .api instead of .internal on the function calls
@lee don't meant to add any pressure - but is there a certain date that the team would target to do a release of the fix?
sorry, probably not great to be asking this over the weekend!
I'll fix this on Monday @conradkoh
@ampp that doesn't sounds like the same issue as in this thread? Can you open a new thread with the reproduction?
thanks Michal!
@conradkoh Fixed, please upgrade.
thanks @Michal Srb, this fixes it.