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

fix: Handle excludeLarge properties for arrays properly#1265

Merged
danieljbruce merged 44 commits into1242-to-main-2from
1242-write-tests-on-save-with-fix
Aug 28, 2024
Merged

fix: Handle excludeLarge properties for arrays properly#1265
danieljbruce merged 44 commits into1242-to-main-2from
1242-write-tests-on-save-with-fix

Conversation

@danieljbruce
Copy link
Copy Markdown
Contributor

@danieljbruce danieljbruce commented Aug 19, 2024

Summary

This PR contains the fix for solving this issue where excludeLargeProperties: true doesn't work properly for arrays. It also ensures that the fix doesn't break existing use cases.

Background

This PR is a successor to this other PR and contains a fix that addresses the failing test cases in the other PR.

Changes

  • entityToEntityProto used to have functionality that would add excludeFromIndexes: true in the right places, but we move this code into a separate addExcludeFromIndexes function because we want to reuse it for arrays.
  • In save the code that calls findLargeProperties_ is moved so that it is only used as is for non array data. For the array data this findLargeProperties_ code is used per element to populate the excludeFromIndexes list in the correct manner.
  • For array data, now that excludeFromIndexes list is correctly calculated we can use the addExcludeFromIndexes functionality that we pulled out to apply excludeFromIndexes: true in the right places.

Next Steps

  • Add an integration test containing the code mentioned in the issue.
  • Add integration tests that uses the JSON array of tests from this PR.
  • Make the save function more modular.
  • Add some more test cases just to be sure

Make it contain longStringArray
This is in excludeFromIndexes - replace them with literals.
@product-auto-label product-auto-label bot added size: l Pull request size is large. api: datastore Issues related to the googleapis/nodejs-datastore API. labels Aug 19, 2024
@danieljbruce danieljbruce marked this pull request as ready for review August 19, 2024 15:57
@danieljbruce danieljbruce requested a review from a team as a code owner August 19, 2024 15:57
@danieljbruce danieljbruce requested a review from a team August 19, 2024 15:57
src/index.ts Outdated
@@ -1125,6 +1118,25 @@ class Datastore extends DatastoreRequest {
// This was replaced with a more efficient mechanism in the top-level
// `excludeFromIndexes` option.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

is this TODO still relevant? Does the top-level excludeFromIndexes work the same way as these changes?

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.

I think this TODO can be removed. There is currently code here that adds excludeFromIndexes in the top level and I added code that provides excludeFromIndexes everywhere else based on the path that gets generated. To avoid test failures, the code for adding excludeFromIndexes in the top level is still needed so I don't think this TODO is relevant anymore.

@product-auto-label product-auto-label bot added size: m Pull request size is medium. and removed size: l Pull request size is large. labels Aug 28, 2024
@danieljbruce danieljbruce merged commit 742ae3a into 1242-to-main-2 Aug 28, 2024
@danieljbruce danieljbruce deleted the 1242-write-tests-on-save-with-fix branch August 28, 2024 14:49
danieljbruce added a commit that referenced this pull request Aug 28, 2024
… of nested fields (#1266)

* test: Restrict types inside the save function (#1264)

* Add interfaces that restrict values passed to save

* Add interfaces for save

We need help from the compiler so these interfaces will be useful for determining the shape of the data.

* Modify current interfaces to make a closer match

The interfaces should match the actual data types that get passed in.

* key and data in PrepareEntityObjectResponse option

These properties are actually optional

* Document all the interfaces added for the save fn

* Add two tests showing name/value should be provide

* Make the SaveNonArrayData more specific.

save doesn’t encode strings or ints or any values that don’t have keys properly so we should restrict the interface to what it does include.

* Add header

* Test should be more flexible

* Add a class for elements with ToString

* Define the toString class inline

* Eliminate links to points in code

* test: Add tests that describe how save should encode excludeFromIndexes for a complex case (#1263)

* Write a sample test for what save output should be

* Add a test for a bunch of complex excludeFromIndex

* Change the replace function so it works everywhere

* Modify the expected value

Make it contain longStringArray

* Correct the test for evaluating arrays

* Break up the entityToEntityProto into separate par

* Fix the tests to work with new addExcludeFromIndex

* Revert "Break up the entityToEntityProto into separate par"

This reverts commit 60dabd7.

* Revert "Fix the tests to work with new addExcludeFromIndex"

This reverts commit ba4e82b.

* Remove source code changes

* Skip the test that looks at arrays

* Remove some of the wildcard indexes

This is in excludeFromIndexes - replace them with literals.

* Remove another boolean value from excludeFromIndex

* Eliminate duplicate expectedMutations

* Eliminate duplicate runTest function

* Begin to set up the async tests

* Pack all tests into the async framework

* Delete tests addressed by async

* Get rid of test functions and inline everything

* Add comment

* Add comments describing each test case

* Remove only

* Add another test looks at name/value not in array

* Add a test for excludeLarge properties and name/va

* Fix the test so that the array case matches

Matches the single case

* should pass the right properties for an array

* Rename the test

* Change name to entityName

* Add two tests that capture the array encoding

encoding problem

* Change expected output of arrays

* Remove only

* Add 2 more tests to ensure behaviour is preserved

* Correct test - it should apply excludeFromIndexes

* Update the test for the nested value

* fix: Handle excludeLarge properties for arrays properly (#1265)

* Write a sample test for what save output should be

* Add a test for a bunch of complex excludeFromIndex

* Change the replace function so it works everywhere

* Modify the expected value

Make it contain longStringArray

* Correct the test for evaluating arrays

* Break up the entityToEntityProto into separate par

* Fix the tests to work with new addExcludeFromIndex

* Break up the entityToEntityProto into separate par

* Fix the tests to work with new addExcludeFromIndex

* Revert "Break up the entityToEntityProto into separate par"

This reverts commit 60dabd7.

* Revert "Fix the tests to work with new addExcludeFromIndex"

This reverts commit ba4e82b.

* Remove source code changes

* Skip the test that looks at arrays

* Remove some of the wildcard indexes

This is in excludeFromIndexes - replace them with literals.

* Remove another boolean value from excludeFromIndex

* Eliminate duplicate expectedMutations

* Eliminate duplicate runTest function

* Begin to set up the async tests

* Pack all tests into the async framework

* Delete tests addressed by async

* Get rid of test functions and inline everything

* Add comment

* Add comments describing each test case

* Remove only

* Add another test looks at name/value not in array

* Add a test for excludeLarge properties and name/va

* Fix the test so that the array case matches

Matches the single case

* should pass the right properties for an array

* Rename the test

* Change name to entityName

* Add two tests that capture the array encoding

encoding problem

* Change expected output of arrays

* Remove only

* Add 2 more tests to ensure behaviour is preserved

* Make argument more specific for excludeFromIndexes

* Use excludeLargeProperties for array/non-array cas

* Fix the test to include entity proto

* Correct mistakes in initial implementation

* Don’t skip any of the tests

* Remove only

* Add check for excludeLargeProperties

* Remove TODO

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
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.

2 participants