Parsing a timestamp-string without a timezone-offset using `FromJsonString` throws a confusing message
What version of protobuf and what language are you using? Version: v3.17.3. Language:Python 3.8
What operating system (Linux, Windows, ...) and version? macOS Big Sur Version 11.2
What runtime / compiler are you using (e.g., python version or gcc version) Python 3.8
What did you do? Steps to reproduce the behavior:
>>> from google.protobuf.timestamp_pb2 import Timestamp
>>> date_string = "2021-06-15T09:45:49" # timezone-naive
>>> pb_timestamp = Timestamp().FromJsonString(date_string)
What did you expect to see
ValueError: time data '2021-06-15T09:45:49' does not specify a timezone-offset
What did you see instead?
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/x/.local/share/virtualenvs/y-i29MmNV0/lib/python3.8/site-packages/google/protobuf/internal/well_known_types.py", line 167, in FromJsonString
date_object = datetime.strptime(second_value, _TIMESTAMPFOMAT)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/_strptime.py", line 568, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/_strptime.py", line 349, in _strptime
raise ValueError("time data %r does not match format %r" %
ValueError: time data '2021-06' does not match format '%Y-%m-%dT%H:%M:%S'
The time-data passed in was 2021-06-15T09:45:49, and not just 2021-06 as erroneously reported in the stack-trace.
Anything else we should know about your project / environment
This does not work:
https://github.com/protocolbuffers/protobuf/blob/fb8862f781430f2ebf66dae8ab6ac455ee778f40/python/google/protobuf/internal/well_known_types.py#L148
maybe changing it to this would do the trick?
timezone_offset = value[10:].rfind('-')
took me a while to track down this bug to end up on this issue
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.
This issue is labeled inactive because the last activity was over 90 days ago.
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please reopen it.
This issue was closed and archived because there has been no new activity in the 14 days since the inactive label was added.