-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Dot notation with doesNotMatchKeyInQuery
can throw exceptions when base object doesn't exist
#4740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I believe this bug still exists, though I did see a more recent issue opened with a similar issue using Unless this was recently solved as part of that bug, it should remain open. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Posted fix in comments of #5030, will submit PR later fixing these issues (they are essentially the same). |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Issue Description
When using dot notation on a
doesNotMatchKeyInQuery
query constraint, the query will error if a result from the original query does not have an object for the base queryKey that uses dot notation. The workaround is to add aexists
constraint to the query, though it seems that should be implicit if an error is going to be thrown otherwise.Steps to reproduce
Create
ClassA
andClassB
.Add a pointer field to
ClassB
onClassA
calledclassB
.Create one instance of
ClassB
and two instances ofClassA
On one instance of
ClassA
, attach the pointer to the instance ofClassB
Call the following cloud code function:
Expected Results
Print
Found 1 objects
Actual Outcome
An error saying
Cannot read property 'objectId' of undefined
Adding the line
queryA.exists('classB');
solves the issue, and I get the expected outcome. The error would not occur if there were no instances ofClassA
that did not have theirclassB
pointer, so keep that in mind if a test case is written. If dot notation is used on the queryKey parameter ofdoesNotMatchKeyInQuery
, theexists
call should be implicit. Without knowing the code that is actually being run, it seems like another fix would be to add an undefined check before trying to access the nested field, but the implicitexists
call seems to me to be a more efficient solution.I have not tested this on the other related methods, like
matchesKeyInQuery
, though I imagine results would be similar. I also only tested this on thequeryKey
parameter.Environment Setup
Server
Database
Logs/Trace
Cannot read property 'objectId' of undefined
The text was updated successfully, but these errors were encountered: