-
Notifications
You must be signed in to change notification settings - Fork 107
fix: check property existence for excludeFromIndexes with wildcard #788
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
Conversation
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 What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
Codecov Report
@@ 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. |
@googlebot I signed it! |
@crwilcox or @stephenplusplus could I trouble y'all to have a look here? |
No region tags are edited in this PR.This comment is generated by snippet-bot.
|
Can someone please add this fix already? It is quite the detrimental bug. |
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. |
There was a problem hiding this 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]) { |
There was a problem hiding this comment.
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]) { |
There was a problem hiding this comment.
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] && |
There was a problem hiding this comment.
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[].*', |
There was a problem hiding this comment.
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.
Closed in favour of #1114. |
Fixes #787 🦕
As described in #787,
nodejs-datastore
raisesTypeError: 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 checknon_exist_data
's existence), so this PR makeentity.ts
check their existence before traversing data forexcludeFromIndexes
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: