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 — Accessing blob.custom_time errors on 0 microsecond timestamp · Issue #363 · 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.

Accessing blob.custom_time errors on 0 microsecond timestamp #363

Copy link
Copy link
Closed
#375
Closed
Accessing blob.custom_time errors on 0 microsecond timestamp#363
#375
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

@rconnaughton
rconnaughton
opened on Jan 22, 2021
Issue body actions

Environment details

  • OS type and version: centos 6
  • Python version: 3.7
  • google-cloud-storage version: 1.34.0

Steps to reproduce

  1. Load a blob
  2. Set the custom_time field to a datetime object with 0 microseconds
  3. patch the object with the changes, and then reload the object
  4. Access the custom_time field and observe the value error

Code example

blob = Blob(mybucket, objectname)
blob.reload()
blob.custom_time = datetime(year=2000, month = 1, day = 13, hour = 13, minute = 1, second = 0, microsecond = 0)
blob.patch()
blob.reload()
blob.custom_time
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/google/cloud/storage/blob.py", line 3773, in custom_time
    return _rfc3339_to_datetime(value)_rfc3339_to_datetime
  File "/usr/local/lib/python3.7/site-packages/google/cloud/_helpers.py", line 286, in _rfc3339_to_datetime
    return datetime.datetime.strptime(dt_str, _RFC3339_MICROS).replace(tzinfo=UTC)
  File "/usr/local/lib/python3.7/_strptime.py", line 577, in _strptime_datetime
    tt, fraction, gmtoff_fraction = _strptime(data_string, format)
  File "/usr/local/lib/python3.7/_strptime.py", line 359, in _strptime
    (data_string, format))
ValueError("time data '2000-01-13T13:01:00Z' does not match format '%Y-%m-%dT%H:%M:%S.%fZ'")

As compared to a working example:

blob.custom_time = datetime(year=2000, month = 1, day = 13, hour = 14, minute = 2, second = 0, microsecond = 10)
blob.patch()
blob.reload()
blob.custom_time
datetime.datetime(2000, 1, 13, 14, 2, 0, 10, tzinfo=<UTC>)

Stack trace

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/google/cloud/storage/blob.py", line 3773, in custom_time
    return _rfc3339_to_datetime(value)_rfc3339_to_datetime
  File "/usr/local/lib/python3.7/site-packages/google/cloud/_helpers.py", line 286, in _rfc3339_to_datetime
    return datetime.datetime.strptime(dt_str, _RFC3339_MICROS).replace(tzinfo=UTC)
  File "/usr/local/lib/python3.7/_strptime.py", line 577, in _strptime_datetime
    tt, fraction, gmtoff_fraction = _strptime(data_string, format)
  File "/usr/local/lib/python3.7/_strptime.py", line 359, in _strptime
    (data_string, format))
ValueError("time data '2000-01-13T13:01:00Z' does not match format '%Y-%m-%dT%H:%M:%S.%fZ'")
Reacted by oittaa

Activity

  1. product-auto-label
    added
    api: storageIssues related to the googleapis/python-storage API.
    on Jan 22, 2021
  2. yoshi-automation
    added
    triage meI really want to be triaged.
    on Jan 23, 2021
  3. frankyn
    added
    type: questionRequest for information or clarification. Not an issue.
    and removed
    triage meI really want to be triaged.
    on Jan 25, 2021
  4. frankyn
    self-assigned this
    on Jan 25, 2021
  5. frankyn
    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
    type: questionRequest for information or clarification. Not an issue.
    on Jan 25, 2021
  6. frankyn commented on Jan 25, 2021

    @frankyn
    frankyn
    on Jan 25, 2021
    Contributor
    More actions

    Hi @rconnaughton,

    Thank you for filing this issue. I was able to reproduce it and looks like Cloud Storage returns no fractional microsecond when it's 0 even though the format described in documentation is YYYY-MM-DD'T'HH:MM:SS.SS'Z'.

    The issue with the client is that it always expects the returned value to include microseconds. I'm following up with the backend team to understand if this is the expectation.

    I'll loop back when I learn more. Thank you for your patience!

    Reacted by Ryan Connaugthon
  7. frankyn commented on Feb 1, 2021

    @frankyn
    frankyn
    on Feb 1, 2021
    Contributor
    More actions

    This is a bug in the library. The Storage backend team stated that when milliseconds is 0 the 0 is not returned.

    I'll work on a fix this week. It will require two PRs based on my current understanding, there might be a better solution though and will research / update:

    1. Add a new format to python-cloud-core.
    2. Use the new format in case the format parsing with non-zero milliseconds is included in python-storage.
  8. frankyn
    assigned
    tritone
    and unassigned
    frankyn
    on Feb 8, 2021
  9. tritone
    added 2 commits that reference this issue on Feb 9, 2021

    fix: custom_time decoding without microseconds

    This issue will close once commit 0de2a21 is merged into the 'master' branch.
    0de2a21

    fix: correctly decode times without microseconds

    This issue will close once commit d2e1fc6 is merged into the 'master' branch.
    d2e1fc6
  10. gcf-merge-on-green
    closed this as completedin #375on Feb 10, 2021
  11. gcf-merge-on-green
    added a commit that references this issue on Feb 10, 2021

    fix: correctly decode times without microseconds (#375)

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

    fix: correctly decode times without microseconds (googleapis#375)

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

    fix: correctly decode times without microseconds (googleapis#375)

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