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

fix: check property existence for excludeFromIndexes with wildcard #788

Closed

Conversation

tanishiking
Copy link

@tanishiking tanishiking commented Feb 1, 2021

Fixes #787 🦕

As described in #787, nodejs-datastore raises TypeError: Cannot read property 'entityValue' of undefined if we try to exclude undefined properties from index using .*.

This is because we didn't check the property existence (e.g. for non_exist_data.*, we should check non_exist_data's existence), so this PR make entity.ts check their existence before traversing data for excludeFromIndexes with a wildcard.


Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

@tanishiking tanishiking requested a review from a team as a code owner February 1, 2021 11:16
@product-auto-label product-auto-label bot added the api: datastore Issues related to the googleapis/nodejs-datastore API. label Feb 1, 2021
@google-cla
Copy link

google-cla bot commented Feb 1, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added the cla: no This human has *not* signed the Contributor License Agreement. label Feb 1, 2021
@codecov
Copy link

codecov bot commented Feb 1, 2021

Codecov Report

❗ No coverage uploaded for pull request base (main@a5cc245). Click here to learn what that means.
The diff coverage is n/a.

❗ Current head e408c19 differs from pull request most recent head 96a4c11. Consider uploading reports for the commit 96a4c11 to get more accurate results

@@           Coverage Diff           @@
##             main     #788   +/-   ##
=======================================
  Coverage        ?   98.97%           
=======================================
  Files           ?       11           
  Lines           ?     8260           
  Branches        ?      486           
=======================================
  Hits            ?     8175           
  Misses          ?       83           
  Partials        ?        2           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@tanishiking
Copy link
Author

@googlebot I signed it!

@google-cla google-cla bot added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Feb 1, 2021
@JustinBeckwith
Copy link
Contributor

@crwilcox or @stephenplusplus could I trouble y'all to have a look here?

@snippet-bot
Copy link

snippet-bot bot commented Jun 10, 2021

No region tags are edited in this PR.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Jul 2, 2021
@udnes99
Copy link

udnes99 commented Sep 8, 2021

Can someone please add this fix already? It is quite the detrimental bug.

@meredithslota meredithslota requested a review from a team as a code owner August 24, 2022 16:45
@product-auto-label product-auto-label bot added the size: s Pull request size is small. label Aug 24, 2022
@google-cla google-cla bot added cla: no This human has *not* signed the Contributor License Agreement. and removed cla: yes This human has signed the Contributor License Agreement. labels Aug 24, 2022
@meredithslota meredithslota added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Aug 24, 2022
@google-cla google-cla bot added cla: no This human has *not* signed the Contributor License Agreement. and removed cla: yes This human has signed the Contributor License Agreement. labels Aug 24, 2022
@zomgbre
Copy link

zomgbre commented Sep 21, 2022

It is a huge shame that this is still broken today in 7.0.0. In fact, two years ago my colleague posted about the same issue and the issue was closed with inaccurate information.

Copy link
Contributor

@danieljbruce danieljbruce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine, but a small difference is required in the way we test this feature.

});
} else {
excludePathFromEntity(entity, firstPathPart);
if (entity.properties![firstPathPart]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we just check to see that this property is defined before we move further as that prevents the error from being thrown. Makes sense. There seems to be no value in further traversing a path that the entity will not have any corresponding properties for.

excludePathFromEntity(value, '');
}
});
if (entity.properties![firstPathPart]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we just check to see that this property is defined before we move further as that prevents the error from being thrown. Makes sense. There seems to be no value in further traversing a path that the entity will not have any corresponding properties for.

@@ -857,6 +857,7 @@ export namespace entity {
if (
firstPathPartIsArray &&
// check also if the property in question is actually an array value.
entity.properties![firstPathPart] &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no harm in this. If we don't check for this and entity.properties![firstPathPart] ever happens to be undefined then this will throw an error and I can't imagine that being desirable.

@@ -1677,6 +1677,8 @@ describe('Datastore', () => {
'metadata.otherProperty',
'metadata.obj.*',
'metadata.longStringArray[].*',
'undefinedData.*',
'undefinedArray[].*',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't modify the existing test. We should make a new test that tests for these specific values so we don't lose any existing test coverage.

@danieljbruce
Copy link
Contributor

Closed in favour of #1114.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the googleapis/nodejs-datastore API. cla: no This human has *not* signed the Contributor License Agreement. size: s Pull request size is small.
Projects
None yet
7 participants