Skip to content

Cannot upsert and entity which has a field value equal to {}  #1453

@diegosanchez

Description

@diegosanchez

Environment details

  • OS: Linux **pruned** 4.6.4-1-ARCH #1 SMP PREEMPT Mon Jul 11 19:12:32 CEST 2016 x86_64 GNU/Linux
  • Node.js version: v4.2.3
  • npm version: 2.14.7
  • gcloud-node version: 0.37.0
  • datastore api version: v1beta3

Steps to reproduce

Snippet of code

  const gcloud = require('gcloud');
  const ds = gcloud.datastore( { namespace: "local", /* credentials */ });

  ds.upsert({
    key: "thekey",
    data: {
      custom: {}
    }
  }, callback);

Stack error:

Error: Unsupported field value, [object Object], was provided.
 at Object.encodeValue (/home/diegos/dev/duplicate-detection/node_modules/gcloud/lib/datastore/entity.js:300:9)
 at /home/diegos/dev/duplicate-detection/node_modules/gcloud/lib/datastore/entity.js:373:32
 at Array.reduce (native)
 at Object.entityToEntityProto (/home/diegos/dev/duplicate-detection/node_modules/gcloud/lib/datastore/entity.js:372:43)
 at /home/diegos/dev/duplicate-detection/node_modules/gcloud/lib/datastore/request.js:844:28
 at Array.forEach (native)
 at DatastoreRequest.save (/home/diegos/dev/duplicate-detection/node_modules/gcloud/lib/datastore/request.js:805:12)
 at DatastoreRequest.upsert (/home/diegos/dev/duplicate-detection/node_modules/gcloud/lib/datastore/request.js:904:8)
 at Object.Engine.save (/home/diegos/dev/duplicate-detection/persistence/engine.js:15:17)
 at /home/diegos/dev/duplicate-detection/model/media.js:19:39

The problem

We cannot store an object which has a property equal to an empty object ( not null but {}). According to the RFC 4627 the object below is a valid one:

{
      "custom": {}
}

The RFC 4627 passage:

2.2. Objects

An object structure is represented as a pair of curly brackets
surrounding zero or more name/value pairs (or members). A name is a
string. A single colon comes after each name, separating the name
from the value. A single comma separates a value from a following
name. The names within an object SHOULD be unique.

 object = begin-object [ member *( value-separator member ) ]
 end-object

 member = string name-separator value

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions