This repository was archived by the owner on Feb 20, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 110
This repository was archived by the owner on Feb 20, 2026. It is now read-only.
Should not throw TypeError when saving null for a field with subproperty index-exclusion #1327
Copy link
Copy link
Closed
Labels
api: datastoreIssues related to the googleapis/nodejs-datastore API.Issues related to the googleapis/nodejs-datastore API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Description
Environment details
- OS: N/A
- Node.js version: N/A
- npm version: N/A
@google-cloud/datastoreversion: v9.1.0, but in earlier versions too
Problem statement
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.
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
// 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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api: datastoreIssues related to the googleapis/nodejs-datastore API.Issues related to the googleapis/nodejs-datastore API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.