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's custom_time is lost on upload. · Issue #372 · 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's custom_time is lost on upload. #372

Copy link
Copy link
Closed
#374
Closed
Blob's custom_time is lost on upload.#372
#374
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

@oittaa
oittaa
opened on Feb 5, 2021
Issue body actions

Environment details

  • OS type and version: Debian Buster
  • Python version: Python 3.7.3
  • pip version: pip 18.1 from /usr/lib/python3/dist-packages/pip (python 3.7)
  • google-cloud-storage version: 1.35.1

Steps to reproduce

  1. Create a blob.
  2. Set custom_time.
  3. Upload the blob .
  4. Try to retrieve blob's custom_time.
  5. Expected result is a datatime, but the actual result is None.

If blob's custom_time is set before uploading, it is just lost. My understanding is that the metadata could be uploaded with the object's content at the same time without needing to patch it afterwards.

https://cloud.google.com/storage/docs/uploading-objects#rest-upload-objects

Code example

import datetime
from google.cloud import storage

bucket_name = "my-test-bucket"
blob_name = "test_blob"

client = storage.Client()
bucket = client.get_bucket(bucket_name)

blob = bucket.blob(blob_name)
blob.custom_time = datetime.datetime.now(datetime.timezone.utc)
print("Before upload {}".format(blob.custom_time))
blob.upload_from_string("test")
blob.reload()
print("After upload {}".format(blob.custom_time))
blob.custom_time = datetime.datetime.now(datetime.timezone.utc)
blob.patch()
blob.reload()
print("After patching {}".format(blob.custom_time))

Stack trace

Before upload 2021-02-05 10:24:08.405494+00:00
After upload None
After patching 2021-02-05 10:24:08.814159+00:00

Activity

  1. product-auto-label
    added
    api: storageIssues related to the googleapis/python-storage API.
    on Feb 5, 2021
  2. yoshi-automation
    added
    triage meI really want to be triaged.
    on Feb 6, 2021
  3. oittaa commented on Feb 6, 2021

    @oittaa
    oittaa
    on Feb 6, 2021
    Author
    More actions

    For example content_encoding works as expected.

    Code

    from google.cloud import storage
    
    bucket_name = "my-test-bucket"
    blob_name = "test_blob"
    
    client = storage.Client()
    bucket = client.get_bucket(bucket_name)
    
    blob = bucket.blob(blob_name)
    blob.content_encoding = "gzip"
    print("Before upload {}".format(blob.content_encoding))
    blob.upload_from_string("test")
    blob.reload()
    print("After upload {}".format(blob.content_encoding))

    Output

    Before upload gzip
    After upload gzip
    

    Is the reason that customTime is missing from _WRITABLE_FIELDS? EDIT: Yes it is. Adding "customTime", line fixed the issue.

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

    Lines 92 to 103 in 5c60d24

    _WRITABLE_FIELDS = (
    "cacheControl",
    "contentDisposition",
    "contentEncoding",
    "contentLanguage",
    _CONTENT_TYPE_FIELD,
    "crc32c",
    "md5Hash",
    "metadata",
    "name",
    "storageClass",
    )

    Which is used by _get_writable_metadata.

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

    Lines 1518 to 1547 in 5c60d24

    def _get_writable_metadata(self):
    """Get the object / blob metadata which is writable.
    This is intended to be used when creating a new object / blob.
    See the `API reference docs`_ for more information, the fields
    marked as writable are:
    * ``acl``
    * ``cacheControl``
    * ``contentDisposition``
    * ``contentEncoding``
    * ``contentLanguage``
    * ``contentType``
    * ``crc32c``
    * ``md5Hash``
    * ``metadata``
    * ``name``
    * ``storageClass``
    For now, we don't support ``acl``, access control lists should be
    managed directly through :class:`ObjectACL` methods.
    """
    # NOTE: This assumes `self.name` is unicode.
    object_metadata = {"name": self.name}
    for key in self._changes:
    if key in _WRITABLE_FIELDS:
    object_metadata[key] = self._properties[key]
    return object_metadata

    And which is then used by _get_upload_arguments.

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

    Lines 1549 to 1571 in 5c60d24

    def _get_upload_arguments(self, content_type):
    """Get required arguments for performing an upload.
    The content type returned will be determined in order of precedence:
    - The value passed in to this method (if not :data:`None`)
    - The value stored on the current blob
    - The default value ('application/octet-stream')
    :type content_type: str
    :param content_type: Type of content being uploaded (or :data:`None`).
    :rtype: tuple
    :returns: A triple of
    * A header dictionary
    * An object metadata dictionary
    * The ``content_type`` as a string (according to precedence)
    """
    headers = _get_encryption_headers(self._encryption_key)
    object_metadata = self._get_writable_metadata()
    content_type = self._get_content_type(content_type)
    return headers, object_metadata, content_type

  4. frankyn
    removed
    triage meI really want to be triaged.
    on Feb 8, 2021
  5. yoshi-automation
    added
    triage meI really want to be triaged.
    on Feb 8, 2021
  6. tritone
    added
    status: investigatingThe issue is under investigation, which is determined to be non-trivial.
    and removed
    triage meI really want to be triaged.
    on Feb 8, 2021
  7. tritone
    self-assigned this
    on Feb 8, 2021
  8. 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.
    and removed
    status: investigatingThe issue is under investigation, which is determined to be non-trivial.
    on Feb 8, 2021
  9. tritone commented on Feb 8, 2021

    @tritone
    tritone
    on Feb 8, 2021
    Contributor
    More actions

    I was able to reproduce this and discovered custom_time was missing from attributes to set during blob creation. Will send a PR with a fix.

    Reacted by oittaa
  10. tritone
    added a commit that references this issue on Feb 8, 2021

    fix: set custom_time on uploads

    This issue will close once commit 788879f is merged into the 'master' branch.
    788879f
  11. tritone
    closed this as completedin #374on Feb 8, 2021
  12. tritone
    added a commit that references this issue on Feb 8, 2021

    fix: set custom_time on uploads (#374)

    This issue will close once commit f048be1 is merged into the 'main' branch.
    f048be1
  13. oittaa
    added 2 commits that reference this issue on Feb 13, 2021

    Fixed now: googleapis/python-storage/issues/372

    13a87bd

    Fixed googleapis/python-storage/issues/372

    5c3e6d9
  14. cojenco
    added 2 commits that reference this issue on Oct 13, 2021

    fix: set custom_time on uploads (googleapis#374)

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

    fix: set custom_time on uploads (googleapis#374)

    This issue will close once commit 4730888 is merged into the 'main' branch.
    4730888
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.