You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
'Table.insert_data' does not support Datetime values #2957
@daspecster Perhaps your environment is different? I'm still seeing the issue, and it's exceedingly easy to reproduce.
Create a Python2.7 virtualenv. Activate it, obviously.
pip install google-cloud-bigquery (currently resolves to the latest version on pip: google_cloud_bigquery-0.23.0-py2.py3-none-any)
Make sure you're authenticated and create a test project. Do this in python interactvely:
>>> from google.cloud import bigquery
>>> import datetime
>>> client = bigquery.Client(project='myproject-1803')
>>> dataset = client.dataset('testset')
>>> dataset.create()
>>> table = dataset.table('test_datefield')
>>> table.schema = (bigquery.SchemaField('name', 'STRING'), bigquery.SchemaField('birthday', 'DATETIME'))
>>> table.create()
>>> table.insert_data(rows=[('Ken', datetime.datetime.now())])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/kkinder/bigquerytest/testenv/lib/python2.7/site-packages/google/cloud/bigquery/table.py", line 770, in insert_data
data=data)
File "/Users/kkinder/bigquerytest/testenv/lib/python2.7/site-packages/google/cloud/_http.py", line 294, in api_request
data = json.dumps(data)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 243, in dumps
return _default_encoder.encode(obj)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 207, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 270, in iterencode
return _iterencode(o, 0)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 184, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: datetime.datetime(2017, 3, 30, 14, 23, 50, 699725) is not JSON serializable
It's also a pretty common thing with Python's json library. Any time you pass a datetime object, this happens. The question is, what is the other end expecting for formatting?
@tswast I'm running up against the difference in the JSON representation of datetime for row values (i.e., floating point seconds to microsecond precisions) vs. query parameters (ISO strings). I'm assuming that is a known issue (or design choice): are there other types where the row value representation is known to differ from query parameter representation?
Activity
daspecster commentedon Jan 23, 2017
Thanks for reporting @inkrement!
daspecster commentedon Mar 3, 2017
@inkrement I haven't been able to reproduce this locally. Are you on the latest version of the library?
inkrement commentedon Mar 4, 2017
I installed it directly from the pip repository. But I don't use the library anymore so I don't know :/
lukesneeringer commentedon Mar 4, 2017
@daspecter Make sure there is a test for this case. If there already is, point to it and close this. If there is not, make one and post a PR.
daspecster commentedon Mar 6, 2017
I believe this is covered in this system test.
kkinder commentedon Mar 30, 2017
@daspecster Perhaps your environment is different? I'm still seeing the issue, and it's exceedingly easy to reproduce.
It's also a pretty common thing with Python's json library. Any time you pass a datetime object, this happens. The question is, what is the other end expecting for formatting?
[-]Datetime not supported[/-][+]'Table.insert_data' does not support Datetime values[/+]tseaver commentedon May 16, 2017
@tswast I'm running up against the difference in the JSON representation of datetime for row values (i.e., floating point seconds to microsecond precisions) vs. query parameters (ISO strings). I'm assuming that is a known issue (or design choice): are there other types where the row value representation is known to differ from query parameter representation?
Marshal row data correctly in 'Table.insert_data()' (#3426)