Open mrnagydavid opened 1 month ago
@google-cloud/datastore
save({ excludeFromIndexes: ['foo.bar'], entity: { sho: 1, foo: null }) // throws TypeError: Cannot read properties of undefined (reading 'properties') save({ excludeFromIndexes: ['foo[].*'], entity: { sho: 1, foo: null }) // throws TypeError: Cannot read properties of undefined (reading 'values')
Considering the following 4 types of index exclusions:
excludeFromindexes: ['foo.*']
excludeFromindexes: ['foo.bar']
excludeFromindexes: ['foo[].*']
excludeFromindexes: ['foo[].bar']
Supplying { entity: { foo: null } } throws for 2 and 3, but not for 1 and 4.
{ entity: { foo: null } }
It should either throw in all cases or in none. I think it should throw in none, and it is easily fixable.
Easily reproducable via unit tests: repo with unit test showcasing error
// entity.ts function excludePathFromEntity(entity: EntityProto, path: string) { if (!entity) return; // <-- !! fixes 'foo.bar' // ... } else if ( firstPathPartIsArray && hasWildCard && remainderPath === '*' && isFirstPathPartDefined ) { const array = entity.properties![firstPathPart].arrayValue; if (!array) return; // <-- !! fixes 'foo[].*' // ...
This TypeError can be fixed with 2 lines of code and I am ready to open a PR.
@mrnagydavid Instead of modifying the test, please add a new test that matches what you changed the old test to. After that it LGTM.
@danieljbruce PR is open with the suggested change.
Environment details
@google-cloud/datastore
version: v9.1.0, but in earlier versions tooProblem statement
Considering the following 4 types of index exclusions:
excludeFromindexes: ['foo.*']
excludeFromindexes: ['foo.bar']
excludeFromindexes: ['foo[].*']
excludeFromindexes: ['foo[].bar']
Supplying
{ entity: { foo: null } }
throws for 2 and 3, but not for 1 and 4.It should either throw in all cases or in none. I think it should throw in none, and it is easily fixable.
Steps to reproduce
Easily reproducable via unit tests: repo with unit test showcasing error
Proposed solution
This TypeError can be fixed with 2 lines of code and I am ready to open a PR.