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

Model.get returns undefined for querying an unknown entity when using Redis caching #119

Closed
Maher4Ever opened this issue Aug 22, 2018 · 4 comments

Comments

@Maher4Ever
Copy link
Contributor

Hello,

I started using the Redis caching feature yesterday and my app immediately broke :(

After looking into it I found an inconsistency in the behavior of the get method of models based on whether caching is enabled or not.

Here is an example that reproduces the issue:

const redisStore = require('cache-manager-redis-store');
const Datastore = require('@google-cloud/datastore');

const gstore = require('gstore-node')({
  cache: [{ store: redisStore }]
});

gstore.connect(new Datastore);

const { Schema } = gstore;

const userSchema = new Schema({
  name: { type: String, required: true }
})

const User = gstore.model('User', userSchema);

const run = async () => {
  try {
    const user = await User.get('user')
    console.log(user)
  } catch (e) {
    console.error(e)
  }
}

run()

If you run this code, it will output undefined. However, if you disable caching, a GstoreError exception is thrown (which in my opinion is the thing I would expect)

@sebelga
Copy link
Owner

sebelga commented Aug 22, 2018

Hi
Thanks for reporting this. You're right, the behavior should be consistent. I will add a fix asap.
Cheers 👍

@sebelga
Copy link
Owner

sebelga commented Aug 26, 2018

Hi,
I just made a release, v4.2.6 that should fix this issue. Could you try it and let me know if it did the fix?
Also make sure that it installs with it nsql-cache v1.1.4 and nsql-cache-datastore v1.1.4.
Cheers!

@Maher4Ever
Copy link
Contributor Author

Hello, I can confirm that the new release fixes this issue 🎊

@sebelga
Copy link
Owner

sebelga commented Aug 27, 2018

Great, thanks for the feedback!

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

No branches or pull requests

2 participants