Local Spanner Emulator doesn't support untyped params for datetime and date
andrii-harbour opened this issue · 2 comments
andrii-harbour commented
Environment details
- OS type and version:
MacOS Sonoma 14.3.1
- Python version:
3.12.2
- pip version:
23.2.1
google-cloud-spanner
version:3.47.0
Steps to reproduce
- Connect to Google Spanner Emulator
- Make sure there is a table with datetime/date column
- Run the python code - get an error
- Retry the same being connected to the Cloud Spanner, no errors
Code example
In the code below, based on the updates from https://github.com/googleapis/python-spanner/releases/tag/v3.43.0 , I am not passing param_types
from datetime import datetime
from google.auth.credentials import AnonymousCredentials
from google.cloud import spanner
client = spanner.Client(
project="localhost",
client_options={"api_endpoint": "localhost:9010"},
credentials=AnonymousCredentials(),
)
instance = client.instance("local-instance")
database = instance.database("local-database")
with database.snapshot() as snapshot:
results = snapshot.execute_sql(
"SELECT * FROM groups WHERE created_at = @created_at", params={"created_at": datetime.now()}
)
print(results.to_dict_list())
Stack trace
File "/Users/aorlov/dev/interpreters/mvp/lib/python3.12/site-packages/google/cloud/spanner_v1/streamed.py", line 151, in __iter__
self._consume_next()
File "/Users/aorlov/dev/interpreters/mvp/lib/python3.12/site-packages/google/cloud/spanner_v1/streamed.py", line 123, in _consume_next
response = next(self._response_iterator)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/aorlov/dev/interpreters/mvp/lib/python3.12/site-packages/google/cloud/spanner_v1/snapshot.py", line 88, in _restart_on_unavailable
iterator = method(request=request)
^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/aorlov/dev/interpreters/mvp/lib/python3.12/site-packages/google/cloud/spanner_v1/services/spanner/client.py", line 1444, in execute_streaming_sql
response = rpc(
^^^^
File "/Users/aorlov/dev/interpreters/mvp/lib/python3.12/site-packages/google/api_core/gapic_v1/method.py", line 131, in __call__
return wrapped_func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/aorlov/dev/interpreters/mvp/lib/python3.12/site-packages/google/api_core/timeout.py", line 120, in func_with_timeout
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/aorlov/dev/interpreters/mvp/lib/python3.12/site-packages/google/api_core/grpc_helpers.py", line 174, in error_remapped_callable
raise exceptions.from_grpc_error(exc) from exc
google.api_core.exceptions.InvalidArgument: 400 Unable to infer type for parameter created_at. Provide the type binding TIMESTAMP
Thanks in advance!
caio-pizzol commented
+1
larkee commented
Thank you for filing this issue! 🙏
I have filed GoogleCloudPlatform/cloud-spanner-emulator/issues/174 in the emulator repo and will follow up with updates there 👍