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 — Blob.metadata not preserved when uploading new file content · Issue #293 · 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.

Blob.metadata not preserved when uploading new file content #293

Copy link
Copy link
Closed
#298
Closed
Blob.metadata not preserved when uploading new file content#293
#298
Copy link
Assignees
HemangChothani
Labels
api: storageIssues related to the googleapis/python-storage API.type: questionRequest for information or clarification. Not an issue.

Description

@lrowe
lrowe
opened on Oct 13, 2020
Issue body actions

blob.metadata is not preserved when uploading new file content on an existing Blob instance with blob.upload_from_string(...) unless you first reset it with blob.metadata = blob.metadata.

I suspect this bug / surprising behaviour is the result of the somewhat awkward mapping of the REST API onto mutable objects. It feels like setting metadata should really be a parameter of the blob upload methods instead of a mutable field on the instance.

Environment details

  • OS type and version:

Both locally on my Mac and within Google Cloud Functions

  • Python version: python --version

Python 3.8.5

  • pip version: pip --version

pip 20.1.1

  • google-cloud-storage version: pip show google-cloud-storage

google-cloud-storage==1.31.2

Steps to reproduce

See code example.

Code example

>>> b = bucket.blob('testme1')
>>> b.metadata = {'test': 'me'}
>>> b.upload_from_string('foo')
>>> b.metadata
{'test': 'me'}
>>> b.upload_from_string('bar')
>>> b.metadata
>>> # Note how b.metadata is not blank

>>> b = bucket.blob('testme2')
>>> b.metadata = {'test': 'me'}
>>> b.upload_from_string('foo')
>>> b.metadata
{'test': 'me'}
>>> b.metadata = b.metadata # <-- workaround
>>> b.upload_from_string('bar')
>>> b.metadata
{'test': 'me'}
>>> # Note how b.metadata is now preserved

Activity

  1. product-auto-label
    added
    api: storageIssues related to the googleapis/python-storage API.
    on Oct 13, 2020
  2. HemangChothani
    self-assigned this
    on Oct 14, 2020
  3. HemangChothani commented on Oct 14, 2020

    @HemangChothani
    HemangChothani
    on Oct 14, 2020
    Contributor
    More actions

    @lrowe Yes it's reproducible, thanks for opening the issue.
    First time when set blob.metadata = {'test': 'me'} it's there in self._changes when called _get_writable_metadata method and response set into the properties.

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

    Line 1482 in fcd1c4f

    for key in self._changes:

    But when called method second time with the same blob object metadata is not in self._changes list so it's doesn't include in writable_metadata so in the response metadata is missing and blob.metadata returns None.

    @frankyn @tseaver Need a suggestion. If it's necessary to preserve metadata then can we have a static for metadata exist in properties in _get_writable_metadata method.

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

    Line 1457 in fcd1c4f

    def _get_writable_metadata(self):

  4. HemangChothani
    added
    type: questionRequest for information or clarification. Not an issue.
    on Oct 14, 2020
  5. gcf-merge-on-green
    closed this as completedin #298on Nov 11, 2020
  6. gcf-merge-on-green
    added a commit that references this issue on Nov 11, 2020

    fix: preserve metadata value (#298)

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

    fix: preserve metadata value (googleapis#298)

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

    fix: preserve metadata value (googleapis#298)

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

Metadata

Metadata

Assignees

  • @HemangChothani
    HemangChothani

Labels

api: storageIssues related to the googleapis/python-storage API.type: questionRequest for information or clarification. Not an issue.

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.