GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Datastore fails when saving entity with null attribute value · Issue #1022 · googleapis/google-cloud-node

Datastore fails when saving entity with null attribute value #1022

New issue
Copy link
New issue
Copy link
Closed
Closed
Datastore fails when saving entity with null attribute value#1022
Copy link
Assignees
stephenplusplus
Labels
api: datastoreIssues related to the Datastore API.

Description

@toboid
toboid
opened on Dec 14, 2015
Issue body actions

When trying to save an object that has null property values gcloud-node errors:

dataset.insert({
  key: dataset.key('Test'),
  data: { foo: 'bar', baz: null }
}, err => {
  if (err) return console.log(err);
});

prints:

Error: Unsupported field value, null, is provided.

I can see that the definition for Value in the Datastore proto buffers api does not provide for null values. The Ruby and Python clients create a message with no value attribute, is this an option for gcloud-node? I'd be really pleased to take a look at this if you'll take a pull request?

Activity

  1. stephenplusplus commented on Dec 14, 2015

    @stephenplusplus
    stephenplusplus
    on Dec 14, 2015
    Contributor
    More actions

    Definitely, that would be very welcome!

    // @pcostell - makes sense, right?

  2. stephenplusplus
    added
    enhancement
    api: datastoreIssues related to the Datastore API.
    on Dec 14, 2015
  3. pcostell commented on Dec 14, 2015

    @pcostell
    pcostell
    on Dec 14, 2015
    Contributor
    More actions

    Makes sense to me. Can we make sure this gets updated for the v1beta3 branch as well? In particular the next version of the API includes NullValue as an explicit field: https://github.com/google/googleapis/blob/master/google/datastore/v1beta3/entity.proto#L119

  4. toboid commented on Dec 14, 2015

    @toboid
    toboid
    on Dec 14, 2015
    Author
    More actions

    OK great. Correctly saving the null to datastore is straightforward, however when the entity is retrieved the null value comes back out as an empty array because this function isn't able to distinguish between a property representing an empty array and a property representing a null value since they have the exact same structure:

    {
      "key": {
        ...
      },
      "property": [
        {
          "name": "i-am-a-null",
          "value": {
            "boolean_value": null,
            "integer_value": null,
            "double_value": null,
            "timestamp_microseconds_value": null,
            "key_value": null,
            "blob_key_value": null,
            "string_value": null,
            "blob_value": null,
            "entity_value": null,
            "list_value": [],
            "meaning": null,
            "indexed": true
          }
        },
        {
          "name": "i-am-an-empty-array",
          "value": {
            "boolean_value": null,
            "integer_value": null,
            "double_value": null,
            "timestamp_microseconds_value": null,
            "key_value": null,
            "blob_key_value": null,
            "string_value": null,
            "blob_value": null,
            "entity_value": null,
            "list_value": [],
            "meaning": null,
            "indexed": true
          }
        }
      ]
    }

    I'm still looking into how to handle this, do you have any suggestions? Should be easier for the v1beta3 branch.

  5. stephenplusplus commented on Dec 15, 2015

    @stephenplusplus
    stephenplusplus
    on Dec 15, 2015
    Contributor
    More actions

    That makes for a tricky problem, indeed. Can we glean any insight into handling this from the other client libraries?

  6. stephenplusplus commented on Dec 17, 2015

    @stephenplusplus
    stephenplusplus
    on Dec 17, 2015
    Contributor
    More actions

    @pcostell added nullValue support to the v1beta3 PR 👍

  7. mcfarljw commented on Dec 20, 2015

    @mcfarljw
    mcfarljw
    on Dec 20, 2015
    Contributor
    More actions

    I'm also finding it a bit quirky to deal with nulls being returned as empty arrays.

  8. toboid commented on Dec 20, 2015

    @toboid
    toboid
    on Dec 20, 2015
    Author
    More actions

    I have the changes to correctly store null values here but still can't see a solution for getting them back out correctly at the moment

  9. pcostell commented on Dec 21, 2015

    @pcostell
    pcostell
    on Dec 21, 2015
    Contributor
    More actions

    The Google versions of protobuf support this using the hasField method, which allows querying for whether a field has been explicitly set or not. There is an issue in the protobufjs issue tracker for this.

    As mentioned above, this is fixed in v1beta3 (mostly because v1beta3 uses proto3, where unset and the default value are considered the same thing).

  10. stephenplusplus commented on Jan 4, 2016

    @stephenplusplus
    stephenplusplus
    on Jan 4, 2016
    Contributor
    More actions

    Let's just wait for v1beta3 to have official support for this. It sounds like it's quite a hassle to support it now and v1beta3 is on the horizon. Support is ready in my v1beta3 PR, so I'm going to close the issue, but please re-open if there's something we can do to support it now.

  11. stephenplusplus
    closed this as completedon Jan 4, 2016
  12. toboid commented on Jan 4, 2016

    @toboid
    toboid
    on Jan 4, 2016
    Author
    More actions

    Makes sense, I can't see a non-hacky way to correctly retrieve nulls at the moment.

  13. krisnye commented on Jan 21, 2016

    @krisnye
    krisnye
    on Jan 21, 2016
    More actions

    I have a fork which adds support for writing null values to the datastore today via a trivial fix. It does NOT fix the problem with reading them as empty arrays. (Not a problem for my use case.)

    https://github.com/krisnye/gcloud-node

  14. JustinBeckwith
    assigned
    stephenplusplus
    on Feb 1, 2021
  15. sofisl
    added a commit that references this issue on Feb 5, 2026

    build: have Kokoro grab service account credentials from secret that …

    5d96235
  16. sofisl
    added a commit that references this issue on Feb 17, 2026

    build: have Kokoro grab service account credentials from secret that …

    0673376
  17. GautamSharda
    added 2 commits that reference this issue on Mar 11, 2026

    feat: move ts target to es2018 from es2016 (#1022)

    d2351f5

    chore: release 2.2.0 (#1023)

    91982a8
  18. feywind
    added a commit that references this issue on Mar 27, 2026

    chore: release 2.2.0 (#1023)

    7d27ae9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @stephenplusplus
    stephenplusplus

Labels

api: datastoreIssues related to the Datastore API.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.