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 — setMetadata() method merges existing with new data? · Issue #597 · googleapis/google-cloud-node

setMetadata() method merges existing with new data? #597

New issue
Copy link
New issue
Copy link
Closed
#607
Closed
setMetadata() method merges existing with new data?#597
#607
Copy link
Assignees
ryanseys
Labels
api: storageIssues related to the Cloud Storage API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.type: questionRequest for information or clarification. Not an issue.
Milestone
Storage Stable

Description

@jgeewax
jgeewax
opened on May 13, 2015
Issue body actions

Looks like if I call setMetadata on an object, it merges the data with what's in production...

var bucket = ...; // Get a bucket somehow.
var file = bucket.file('my-file');

file.setMetadata({
  metadata: {
    first: 'first'
  }
});

file.setMetadata({
  metadata: {
    second: 'second'
  }
}, function(err, metadata) {
  // metadata here is {first: 'first', second: 'second'}
  // Expected it to be just {second: 'second'} ....
});

I suspect that we can't .. fix this all that much... but maybe we can at least document it ?


The options we have so far:

  • Make metadata immutable: remove setMetadata
  • Operate on a single attribute at a time: getMetadata(key) and setMetadata(key, value)
  • Rename setMetadata to patchMetadata or mergeMetadata
  • Add some documentation about the behavior of setMetadata

/cc @Capstan @aozarov

Activity

Next
  1. jgeewax
    added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    api: storageIssues related to the Cloud Storage API.
    on May 13, 2015
  2. jgeewax
    added this to the Storage Stable milestone on May 13, 2015
  3. jgeewax
    added
    type: questionRequest for information or clarification. Not an issue.
    on May 13, 2015
  4. ryanseys commented on May 13, 2015

    @ryanseys
    ryanseys
    on May 13, 2015
    Contributor
    More actions

    Remember #459? Yeah we switched to PATCH because using PUT destroyed ACLs with BigQuery, making our datasets inaccessible. I'm not sure if this is also the case with Storage but I feel it would be appropriate to remain consistent across our APIs in this library.

  5. ryanseys commented on May 13, 2015

    @ryanseys
    ryanseys
    on May 13, 2015
    Contributor
    More actions

    We can still document it for our users. If they want to delete an existing value, I believe the correct way is to set it to null.

  6. aozarov commented on May 13, 2015

    @aozarov
    aozarov
    on May 13, 2015
    More actions

    Yes, but I doubt if doing it (delete and set) should be done by the library as it can fail in the middle and leave it in an undesired state.

    BTW, nulls may be a separate issue which I mentioned to @jgeewax.
    In Java nulls are considered as "ignore" in patch operation and instead a special "null" value should be used (e.g. http://javadoc.google-http-java-client.googlecode.com/hg/latest/com/google/api/client/util/Data.html#NULL_BIG_DECIMAL) [which clearly should be done transparently by the library]. Not sure if the same problem applies to node.js apiary client.

  7. ryanseys commented on May 13, 2015

    @ryanseys
    ryanseys
    on May 13, 2015
    Contributor
    More actions

    I doubt if doing it (delete and set) should be done by the library as it can fail in the middle and leave it in an undesired state.

    The API call operation is atomic so either the whole thing succeeds or fails.

  8. ryanseys commented on May 13, 2015

    @ryanseys
    ryanseys
    on May 13, 2015
    Contributor
    More actions

    I think I see what you were saying. I meant that using PATCH you can delete existing values by setting them to null. We never make 2 calls for setting metadata. That requires you to know about the ones are set already, which is a getMetadata call away. We leave this as an exercise for the user if they want to do that.

  9. aozarov commented on May 13, 2015

    @aozarov
    aozarov
    on May 13, 2015
    More actions

    What I was saying is that we should probably not do the following:

    func setMetadata(blob, metadata) {
      rpc.patch(blob, {"metadata": null})
      rpc.patch(blob, {"metadata": metadata})
    }
    
  10. ryanseys commented on May 13, 2015

    @ryanseys
    ryanseys
    on May 13, 2015
    Contributor
    More actions

    Oh we'd never do that. The end result is the same as just rpc.patch(blob, {"metadata": metadata})

    I meant if you wanted to set completely new metadata, including destroying the ones currently set, you need to know the existing ones and set them to null so as to achieve the same result as using PUT.

  11. ryanseys commented on May 13, 2015

    @ryanseys
    ryanseys
    on May 13, 2015
    Contributor
    More actions

    Like this:

    // metadata is currently { a: '1', b: '2', c: '3' };
    rpc.patch(blob, { metadata: { a: 'x', b: null, c: null } }) // need to know b and c exist so you can set them to null
    // metadata is now { a: 'x' };

    This is the same as:

    // metadata is currently { a: '1', b: '2', c: '3' };
    rpc.put(blob, { metadata: { a: 'x' } })
    // metadata is now { a: 'x' };
  12. aozarov commented on May 13, 2015

    @aozarov
    aozarov
    on May 13, 2015
    More actions

    Is it? Is rpc.put doing an update (https://cloud.google.com/storage/docs/json_api/v1/objects/update)?
    If so, wouldn't it clear out the other Blob's user-given properties (e.g. contentLanguage)?

  13. jgeewax commented on May 13, 2015

    @jgeewax
    jgeewax
    on May 13, 2015
    ContributorAuthor
    More actions

    So back to the main issue:

    My concern here is that set typically means "replace the value up there with the value I'm sending from down here". set to us means... "merge this value from down here into whatever data exists up there."

    Can we rename anything ? or are we just OK with adding some docs that explain this? Or do we try to get Google to fix something ? What makes the most sense as a user of this library?

  14. aozarov commented on May 13, 2015

    @aozarov
    aozarov
    on May 13, 2015
    More actions

    I doubt that a function that can only append is that useful.
    One options (until fixed by the backed) would be to make it a read-only property which can only be set when creating a new file. Once apiary fix the issue property can become again read-write.

  15. 34 remaining items

  16. GautamSharda
    added a commit that references this issue on Feb 2, 2026

    feat: propagate spanIds (#599)

    This issue will close once commit 7fcfd40 is merged into the 'main' branch.
    7fcfd40
  17. sofisl
    added a commit that references this issue on Feb 3, 2026

    build: use c8 for coverage (#597)

    af005a4
  18. GautamSharda
    added a commit that references this issue on Feb 3, 2026

    feat: propagate spanIds (#599)

    This issue will close once commit 88af461 is merged into the 'main' branch.
    88af461
  19. sofisl
    added a commit that references this issue on Feb 4, 2026

    fix: Update dependency @google-cloud/logging from 9.0.0 to 9.8.0 (#597)

    17bc710
  20. sofisl
    added a commit that references this issue on Feb 25, 2026

    Release v2.4.2 (#597)

    c1f16b0
  21. GautamSharda
    added a commit that references this issue on Feb 25, 2026

    Revert "chore: revert previous node-version template updates (#593)" (#…

    aaf8776
  22. GautamSharda
    added 3 commits that reference this issue on Mar 11, 2026

    build: allow Node 10 to push to codecov (#597)

    35e2e56

    fix: typeo in nodejs .gitattribute (#597)

    4cdc4d8

    chore: release 3.3.2 (#598)

    43b0f01
  23. sofisl
    added a commit that references this issue on Mar 17, 2026

    fix: Do Not Mutate Config for Redacted Retries (#597)

    e705a71
  24. thiyaguk09
    added a commit that references this issue on Mar 18, 2026

    Release v2.4.2 (googleapis#597)

    3b9c50f
  25. GautamSharda
    added 2 commits that reference this issue on Mar 23, 2026

    build: use c8 for coverage (#597)

    ab69f42

    build: use c8 for coverage (#597)

    6196409
  26. shivanee-p
    added a commit that references this issue on Mar 27, 2026

    build: use c8 for coverage (#597)

    463e41d
  27. thiyaguk09
    added a commit that references this issue on May 5, 2026

    build: use c8 for coverage (googleapis#597)

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

Metadata

Metadata

Assignees

  • @ryanseys
    ryanseys

Labels

api: storageIssues related to the Cloud Storage API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

    Milestone

    • Storage Stable

    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.