nodejs-datastore icon indicating copy to clipboard operation
nodejs-datastore copied to clipboard

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

Open tanishiking opened this issue 4 years ago • 2 comments

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 https://github.com/googleapis/nodejs-datastore/pull/451

tanishiking avatar Feb 01 '21 11:02 tanishiking

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.

danieljbruce avatar May 30 '22 19:05 danieljbruce

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.

tanishiking avatar May 31 '22 05:05 tanishiking

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 avatar Mar 06 '23 15:03 danieljbruce

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

danieljbruce avatar Mar 08 '23 16:03 danieljbruce