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 exclude from indexes with wildcard #1114

Conversation

danieljbruce
Copy link
Contributor

@danieljbruce danieljbruce commented May 26, 2023

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 as code owners 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
src/entity.ts Outdated Show resolved Hide resolved
src/entity.ts Outdated Show resolved Hide 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’
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
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 () => {
Copy link
Contributor

@ruyadorno ruyadorno Sep 29, 2023

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
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
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.
Copy link
Contributor

@ruyadorno ruyadorno left a comment

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
15 checks passed
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. size: m Pull request size is medium.
Projects
None yet
2 participants