Skip to content
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

Error when using nsql cache getting multiple keys in Model.get. #187

Closed
aroraenterprise opened this issue Sep 23, 2019 · 9 comments · Fixed by #198
Closed

Error when using nsql cache getting multiple keys in Model.get. #187

aroraenterprise opened this issue Sep 23, 2019 · 9 comments · Fixed by #198

Comments

@aroraenterprise
Copy link

This happens all of a sudden when nsql cache is enabled. When i do a Model.get() for multiple ids, it will work and then all of a sudden this error comes up.

Error: Key cannot be undefined. at keyToString (~/node_modules/nsql-cache-datastore/lib/index.js:96:23)

@sebelga
Copy link
Owner

sebelga commented Sep 23, 2019

Hello,
Thanks for reporting. In order to reproduce I would need a bit more context as when this error appears. Do you know the steps that trigger that error apart from turning on the cache?

Also, could you share the full stack trace of the errors?
Thanks!

@aroraenterprise
Copy link
Author

Okay, I got it to reproduce. This error occurs very specifically when:
First, I have one item of let's say Attendee in the store and I use Model.get([attendeeId]) to get this entity -> everything is okay.
Now, I add another entity into the datastore and I go Model.get([attendeeId1, attendeeId2]). With cache enabled this doesn't work. Once I reset the app it starts behaving normally again. It is only when the initial call is for just one item followed by a call for more than one item.

Here is the entire trace:
Error: Key cannot be undefined. at keyToString (/Users/sajarora/Projects/one_day_builds/edropin_uno/backend/node_modules/nsql-cache-datastore/lib/index.js:96:23) at Object._db.keyToString.key [as keyToString] (/Users/sajarora/Projects/one_day_builds/edropin_uno/backend/node_modules/nsql-cache/lib/index.js:171:61) at keyToString (/Users/sajarora/Projects/one_day_builds/edropin_uno/backend/node_modules/nsql-cache/lib/keys.js:17:60) at addToCache (/Users/sajarora/Projects/one_day_builds/edropin_uno/backend/node_modules/nsql-cache/lib/keys.js:127:30) at Array.forEach (<anonymous>) at onResult (/Users/sajarora/Projects/one_day_builds/edropin_uno/backend/node_modules/nsql-cache/lib/keys.js:131:29) at processTicksAndRejections (internal/process/task_queues.js:86:5)

@aroraenterprise
Copy link
Author

From further looking into it, it seems that cache.db.getEntityFromKey(entity) doesn't work when the entity is type of array which is what happens in this situation. I hope this helps you find the problem.

@aroraenterprise
Copy link
Author

I am currently using this hack as a workaround to this issue. I disable cached when there is only one id in the array, and re-enable it when there is more than one.
const entities = await CampaignSchema.get( ids, [], environment.appId, undefined, { preserveOrder: true, cache: ids.length === 1 ? false : true, dataloader: ctx.dataloader, });

@sebelga
Copy link
Owner

sebelga commented Sep 30, 2019

Hi,
Thanks for the update! I will have a look and let you know. Cheers! 👍

@aroraenterprise
Copy link
Author

Hey, just checking for any updates on this issue. Thank you.

@sebelga
Copy link
Owner

sebelga commented Oct 9, 2019

Hi, sorry for the delay. I am very busy until next week. Hopefully, I should be able to look at this at the end of next week. Thanks!

@aroraenterprise
Copy link
Author

That would be amazing! Thank you so much. I know you are very busy.

@sebelga
Copy link
Owner

sebelga commented Oct 26, 2019

Hi!
I've just released v7.2.3 that should fix this bug. Thanks for reporting! Could you please test it and let me know if the issue is indeed solved?

Cheers 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants