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 — Can't delete custom metadata key on object · Issue #381 · googleapis/python-storage

This repository was archived by the owner on Mar 31, 2026. It is now read-only.
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Can't delete custom metadata key on object #381

Copy link
Copy link
Closed
#383
Closed
Can't delete custom metadata key on object#381
#383
Copy link
Assignees
tritone
Labels
api: storageIssues related to the googleapis/python-storage API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Description

@hankd-v
hankd-v
opened on Feb 16, 2021
Issue body actions

I ran into some issues trying to delete a custom metadata key from a storage object. I expected the following to work, but did not result in the key being deleted:

# blob has metadata with key 'foo'
new_metadata = {}
for x in blob.metadata:
    if x != 'foo':
        new_metadata[x] = blob.metadata[x]
# new_metadata is now a copy of the metadata without key 'foo'
blob.metadata = new_metadata
blob.patch()
# The blob's metadata still has key 'foo'

The Rest API indicated to send a value of JSON null associated with the key to perform a deletion, but that doesn't seem to happen when issuing a blob.patch with a metadata with a key removed.

As a work around, I created a copy of the desired metadata, deleted all of the blob's metadata (which does work), then updated the metadata to be the desired metadata.

new_metadata = {}
for x in blob.metadata:
    if x != 'foo':
        new_metadata[x] = blob.metadata[x]
blob.metadata = None
blob.patch()
blob.metadata = new_metadata
blob.patch()

Activity

  1. product-auto-label
    added
    api: storageIssues related to the googleapis/python-storage API.
    on Feb 16, 2021
  2. tritone
    added
    priority: p2Moderately-important priority. Fix may not be included in next release.
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    on Feb 16, 2021
  3. tritone
    self-assigned this
    on Feb 16, 2021
  4. tritone commented on Feb 17, 2021

    @tritone
    tritone
    on Feb 17, 2021
    Contributor
    More actions

    I was able to reproduce the issue from your example.

    I think it's expected that deleting a key would not succeed in overwriting the key when using a patch request. However, I would think that at least by setting a key's value to None, it would be possible to indicate that the key should be deleted by sending null to the API. However, this also fails because of this line here:

    python-storage/google/cloud/storage/blob.py

    Line 3629 in fdabd6a

    value = {k: str(v) for k, v in value.items()}
    -- converting the value to a string means that None is stored as "None"!

    I tested locally and by rewriting the line as follows, we can allow keys to be deleted by setting their value to None:

                value = {k: str(v) if v is not None else None for k, v in value.items()}
    

    @frankyn @andrewsg does this seem like the correct approach to you? If so I'll make a PR (and add it to the docs for metadata that this is how keys can be deleted).

    Reacted by hankd-v
  5. tritone
    added a commit that references this issue on Feb 17, 2021

    fix: allow metadata keys to be cleared

    This issue will close once commit f28be52 is merged into the 'master' branch.
    f28be52
  6. frankyn commented on Feb 17, 2021

    @frankyn
    frankyn
    on Feb 17, 2021
    Contributor
    More actions

    I'm surprised we hadn't seen this before to be honest, but yes, the suggestion LGTM!

  7. tritone
    closed this as completedin #383on Feb 17, 2021
  8. tritone
    added a commit that references this issue on Feb 17, 2021

    fix: allow metadata keys to be cleared (#383)

    This issue will close once commit 79d27da is merged into the 'main' branch.
    79d27da
  9. cojenco
    added 2 commits that reference this issue on Oct 13, 2021

    fix: allow metadata keys to be cleared (googleapis#383)

    This issue will close once commit fccc39f is merged into the 'main' branch.
    fccc39f

    fix: allow metadata keys to be cleared (googleapis#383)

    This issue will close once commit cc78fff is merged into the 'main' branch.
    cc78fff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @tritone
    tritone

Labels

api: storageIssues related to the googleapis/python-storage API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

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.