Skip to content

Accessing blob.custom_time errors on 0 microsecond timestamp #363

@rconnaughton

Description

@rconnaughton

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'")

Metadata

Metadata

Assignees

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