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

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

Closed
tanishiking opened this issue Feb 1, 2021 · 4 comments · Fixed by #1114
Assignees
Labels
api: datastore Issues related to the googleapis/nodejs-datastore API. priority: p3 Desirable enhancement or fix. May not be included in next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@tanishiking
Copy link

tanishiking commented Feb 1, 2021

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

For example,

datastore.save(
  key,
  {
    prop: 'dummy',
  },
  excludeFromIndexes: [
    // this just ignored
    'non_exist_property',
    // causes TypeError: Cannot read property 'entityValue' of undefined`
    // should also be ignored
    'non_exist_property.*' 
  ]
)

As non_exist_property in excludeFromIndexes is ignored, non_exist_property.* should be ignored and we should be able to add data.


This causes a problem when we try to exclude some optional properties like

interface Example {
  prop1: string,
  prop2?: {
    nested1: string,
    nested2: string
  }
}

and want to exclude prop2.* from indexes.

Environment details

  • OS: OSX (but it should happen on any OS)
  • Node.js version: 10.22.1 (but it should happen on any versions)
  • npm version: 6.14.6 (dit)
  • @google-cloud/datastore version: 6.3.1

Steps to reproduce

datastore.save(
  key,
  {
    prop: 'dummy',
  },
  excludeFromIndex: [
    // this just ignored
    'non_exist_property',
    // causes TypeError: Cannot read property 'entityValue' of undefined`
    // should also be ignored
    'non_exist_property.*' 
  ]
)
failing test case
diff --git a/test/index.ts b/test/index.ts
index 42bb76d..f31b52a 100644
--- a/test/index.ts
+++ b/test/index.ts
@@ -1677,6 +1677,8 @@ describe('Datastore', () => {
             'metadata.otherProperty',
             'metadata.obj.*',
             'metadata.longStringArray[].*',
+            'undefinedData.*',
+            'undefinedArray[].*',
           ],
         },
         assert.ifError

Related #451

@product-auto-label product-auto-label bot added the api: datastore Issues related to the googleapis/nodejs-datastore API. label Feb 1, 2021
tanishiking pushed a commit to tanishiking/nodejs-datastore that referenced this issue Feb 1, 2021
@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Feb 2, 2021
@bcoe bcoe added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. labels Feb 5, 2021
@yoshi-automation yoshi-automation removed the triage me I really want to be triaged. label Feb 5, 2021
@yoshi-automation yoshi-automation added 🚨 This issue needs some love. and removed 🚨 This issue needs some love. labels May 8, 2021
@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Aug 1, 2021
@danieljbruce
Copy link
Contributor

The arguments contained inside save function are not a list of valid json objects so this code won't run?

Did you mean?:

const {Datastore} = require('@google-cloud/datastore');
const datastore = new Datastore();

async function datastoreSave() {
  await datastore.save({
    key: {
      prop: 'dummy',
    },
    excludeFromIndexes: [
      'non_exist_property', // this just ignored
      'non_exist_property.*' // should also be ignored
    ]
  });
}

datastoreSave();

If so, I get a different error: InvalidKey: A key should contain at least a kind.

@tanishiking
Copy link
Author

tanishiking commented May 31, 2022

Sorry, I no longer use nodejs datastore, and I don't have plan to work on this in the near future. If anyone is interested in this, please take this over.

@danieljbruce danieljbruce self-assigned this Feb 9, 2023
@danieljbruce
Copy link
Contributor

danieljbruce commented Mar 6, 2023

I was able to reproduce the same error that @tanishiking is talking about with the following script:

const {Datastore} = require('@google-cloud/datastore');
const datastore = new Datastore();

async function datastoreSave() {
  const key = datastore.key(['Post', 'Post1']);
  await datastore.save({
    key,
    data: {},
    excludeFromIndexes: [
      'non_exist_property', // this just ignored
      'non_exist_property.*' // should also be ignored
    ]
  });
}

datastoreSave();

@danieljbruce
Copy link
Contributor

Issue needs SLA signoff in order to move forward. Lowering priority accordingly.

@danieljbruce danieljbruce added priority: p3 Desirable enhancement or fix. May not be included in next release. and removed priority: p2 Moderately-important priority. Fix may not be included in next release. labels Mar 8, 2023
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. priority: p3 Desirable enhancement or fix. May not be included in next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
4 participants