googleapis / python-bigquery

Apache License 2.0
746 stars 306 forks source link

snapshot_definition.snapshot_time throws exception #1986

Open mars-lan opened 3 months ago

mars-lan commented 3 months ago

Environment details

Steps to reproduce

  1. Create a snapshot table
  2. Retrieve snapshot time from snapshot_definition.snapshot_time

Code example

# get a snapshot table
bq_table = client.get_table(...) 

# throws exception
bq_table.snapshot_definition.snapshot_time

Stack trace

...
  File "/usr/local/lib/python3.8/site-packages/google/cloud/bigquery/table.py", line 976, in snapshot_definition
    snapshot_info = SnapshotDefinition(snapshot_info)
  File "/usr/local/lib/python3.8/site-packages/google/cloud/bigquery/table.py", line 1372, in __init__
    self.snapshot_time = google.cloud._helpers._rfc3339_to_datetime(
  File "/usr/local/lib/python3.8/site-packages/google/cloud/_helpers/__init__.py", line 252, in _rfc3339_to_datetime
    return datetime.datetime.strptime(dt_str, _RFC3339_MICROS).replace(tzinfo=UTC)
  File "/usr/local/lib/python3.8/_strptime.py", line 568, in _strptime_datetime
    tt, fraction, gmtoff_fraction = _strptime(data_string, format)
  File "/usr/local/lib/python3.8/_strptime.py", line 349, in _strptime
    raise ValueError("time data %r does not match format %r" %
ValueError: time data '2024-07-23T09:09:09Z' does not match format '%Y-%m-%dT%H:%M:%S.%fZ'

Seems like the library is incorrectly expecting the date string to contain the millisecond portion.