Skip to content
This repository was archived by the owner on Feb 20, 2026. It is now read-only.

fix: Check property existence for exclude from indexes with wildcard - #1114

Merged
danieljbruce merged 40 commits into
googleapis:mainfrom
danieljbruce:check-property-existence-for-excludeFromIndexes-with-wildcard
Sep 29, 2023
Merged

danieljbruce merged 40 commits into
googleapis:mainfrom
danieljbruce:check-property-existence-for-excludeFromIndexes-with-wildcard

Conversation

@danieljbruce

@danieljbruce danieljbruce commented May 26, 2023 •

Copy link
Copy Markdown
Contributor

Changes:

Adds a check in three places for the existence of a property in the path provided for exclude from indexes. Also adds test cases to explore what happens when a property is not contained in exclude from indexes, when the property is contained and when it is contained with an array in the path.

Take a look at the changes in the src folder. All the changes in the PR involve adding an additional check to see if entity.properties![firstPathPart] is defined before accessing a property of entity.properties![firstPathPart]. That solves the issue users are seeing where the code throws an error. Instead it just doesn't explore the non-existent property path further and it doesn't add excludeFromIndexes = true to any of the entity properties.

The exact test case corresponding to the issue the user reported is at https://github.com/googleapis/nodejs-datastore/pull/1114/files#diff-177d97aec07fd5b22f04049b34d74939b1d8364a7a83e8fb69ee3ee8695105fbR2187-R2198, but similar test cases where the same error would occur were added and source code changes were made to address those test cases.

Fixes #787

Testing without mocks allows us to look at the code how it is functioning right now so that we can evaluate the intended behavior.
Objects shared by both tests should be moved into the outer block so that they can be shared.
Now the test fails properly and passes properly by introducing callbacks
The failure should be visible to the user and in the current state it is so now by isolating the test it becomes easier to explore solutions that work.
indent a describe block, modify tests to make sure they pass and refactor a function out that easily allows for testing modified parameters.
Add two more tests that address the array case for excludeIndexesFromPath. Also ensure that the conditions which check for these test cases properly ignore exclude from indexes when an array is used
@danieljbruce
danieljbruce requested review from a team May 26, 2023 15:46
@product-auto-label product-auto-label Bot added size: m Pull request size is medium. api: datastore Issues related to the googleapis/nodejs-datastore API. labels May 26, 2023
@danieljbruce
danieljbruce marked this pull request as draft May 26, 2023 15:55
We should not create a nomocks file because we can just group the tests under a unique describe block of test/index.ts.
@danieljbruce
danieljbruce marked this pull request as ready for review May 26, 2023 17:47
@danieljbruce danieljbruce added the owlbot:run Add this label to trigger the Owlbot post processor. label May 26, 2023
@gcf-owl-bot gcf-owl-bot Bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label May 26, 2023
Comment thread src/entity.ts Resolved
Comment thread src/entity.ts Resolved
danieljbruce and others added 12 commits September 28, 2023 10:16
…into check-property-existence-for-excludeFromIndexes-with-wildcard
Remove typeof and remove check for string ‘undefined’
…ldcard' of https://github.com/danieljbruce/nodejs-datastore into check-property-existence-for-excludeFromIndexes-with-wildcard
Refactor the tests so that they are more readable. There is a lot of repeated code in each test which makes comparisons hard.
Replace all tests exercising the feature so that they all use the same test script. This will make the tests way easier to read.
Add parameterized testing to eliminate repeated code. These tests need to be easier to read for the sake of the reviewer.
This function is only used once now. We should inline this code in the test.
In the test title include the properties passed in so that it is easy to track what passed/failed.
Similar variables should be used together. Organize the code so that there is less confusion about which variables are related.
The getExpectedConfig does not need to be used anymore because its code can just be inlined in the one place it is used.
Separate the test into blocks and inline some parameters for better test readability.
Stronger typing makes the code easier to read.
Don’t assign to the Datastore variable. This is not necessary. Just use the OriginalDatastore variable directly.
The diff will be easier to read if we do not add a nested if statement and instead apply a condition on the if and change the else to else if.
Apply the first suggestion in the PR to all examples
There is a repeated code fragment for checking if the first path part is undefined that we should refactor.
This reverts commit a101f27.
We do four checks to see if the first path part is defined. We should refactor these checks out.
The comment should reflect the next line of code.
@danieljbruce danieljbruce added the owlbot:run Add this label to trigger the Owlbot post processor. label Sep 28, 2023
@gcf-owl-bot gcf-owl-bot Bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Sep 28, 2023
Comment thread test/index.ts Outdated
Comment on lines +2229 to +2231
it(`should pass the right properties to upsert on save with parameters: ${JSON.stringify(
onSaveTest
)}`, async () => {

@ruyadorno ruyadorno Sep 29, 2023 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What if we added a description property to each onSaveTest object with a human-readable, clear description of each scenario (it's probably fine to just reuse the wording for the comments on top of each object definition) and use it here instead of just dropping the blob of JSON.stringify() which I'm afraid will get really unreadable and harder to maintain with time.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sounds good. Then we can use the description as the test name.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

…into check-property-existence-for-excludeFromIndexes-with-wildcard

# Conflicts:
#	test/index.ts
Replace comments with description property so that the tests will report the description when running the tests instead of the properties in the description.

@ruyadorno ruyadorno left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM 👍

@danieljbruce danieljbruce added the owlbot:run Add this label to trigger the Owlbot post processor. label Sep 29, 2023
@gcf-owl-bot gcf-owl-bot Bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Sep 29, 2023
@danieljbruce
danieljbruce merged commit e6b8ef7 into googleapis:main Sep 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: datastore Issues related to the googleapis/nodejs-datastore API. size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

excludeFromIndexes using wildcard on non-existing data causes TypeError: Cannot read property 'entityValue' of undefined.

2 participants

⌂ 换网址