Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtimeconfig: Update time fails to parse #4807

Closed
kw opened this issue Jan 29, 2018 · 7 comments
Closed

Runtimeconfig: Update time fails to parse #4807

kw opened this issue Jan 29, 2018 · 7 comments
Assignees
Labels
api: runtimeconfig Issues related to the Cloud Runtime Config API API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@kw
Copy link

kw commented Jan 29, 2018

OS: Linux (Debian 4.9.65)
Python: 3.5.3 / 2.7.13
Version: google-cloud-runtimeconfig==0.28.0, google-cloud==0.32.0

Steps to reproduce:

  1. Using gcloud, set a runtimeconfig variable.
  2. In Python, load that variable
  3. Try to access its update_time property.
>>> from google.cloud import runtimeconfig
>>> client = runtimeconfig.Client()
>>> config = client.config('testconfig')
>>> var = config.get_variable('foo')
>>> var.update_time
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/redacted/lib/python3.5/site-packages/google/cloud/runtimeconfig/variable.py", line 160, in update_time
    value = _rfc3339_to_datetime(value)
  File "/redacted/lib/python3.5/site-packages/google/cloud/_helpers.py", line 274, in _rfc3339_to_datetime
    dt_str, _RFC3339_MICROS).replace(tzinfo=UTC)
  File "/usr/lib/python3.5/_strptime.py", line 510, in _strptime_datetime
    tt, fraction = _strptime(data_string, format)
  File "/usr/lib/python3.5/_strptime.py", line 343, in _strptime
    (data_string, format))
ValueError: time data '2018-01-22T21:39:44.095040522Z' does not match format '%Y-%m-%dT%H:%M:%S.%fZ'
>>> var._properties
{'text': '43', 'updateTime': '2018-01-22T21:39:44.095040522Z'}

Observation: The %f format accepts microseconds, not fractions of arbitrary precision. That means six digits at most, but I see nine in the data.

@chemelnucfin chemelnucfin added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. api: runtimeconfig Issues related to the Cloud Runtime Config API API. priority: p2 Moderately-important priority. Fix may not be included in next release. labels Jan 31, 2018
@tswast
Copy link
Contributor

tswast commented Jan 31, 2018

Interesting. RuntimeConfig must have started recording nanoseconds somewhat recently.

@jonparrott It seems Python only supports microsecond precision, not nanoseconds.

I'm guessing we should modify the parsing to discard nanoseconds when present.

@tseaver
Copy link
Contributor

tseaver commented Feb 1, 2018

@tswast FWIW, spanner has a non-public TimestampWithNanoseconds (derived from datetime.datetime). We could promote it if that would be useful.

@theacodes
Copy link
Contributor

promote it into api_core? It might be useful because many APIs do expose nanosecond precision.

@tswast
Copy link
Contributor

tswast commented Feb 1, 2018

The from_rfc3339 function there looks very useful. I would bet that more GCP products will be doing nanoseconds.

@theacodes
Copy link
Contributor

@tseaver do you mind filing a bug to promote that class to api_core? (& if you or @chemelnucfin
want to take on a PR to do that, that'd be awesome)

@tseaver
Copy link
Contributor

tseaver commented Feb 2, 2018

@jonparrott see #4829.

@tseaver
Copy link
Contributor

tseaver commented Mar 16, 2018

PR #4979 moved that class into API core, so we should be able to fix this issue using it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: runtimeconfig Issues related to the Cloud Runtime Config API API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

6 participants