Repository navigation
Spanner: Error message for non-existent spanner instance is hard to debug. #8695
Copy link
Copy link
Closed
Labels
api: spannerIssues related to the Spanner API.Issues related to the Spanner API.backendexternalThis issue is blocked on a bug with the actual product.This issue is blocked on a bug with the actual product.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Description
When an invalid (non-existent) instance id is specified the error you receive isn't intuitive.
spanner_client = spanner.Client()
# Get an instance, but provide a non-existent instance id
instance = spanner_client.instance('non_existent_spanner_instance')
database = instance.database('real_database_id_on_different_instance')
with database.snapshot() as snapshot:
results = snapshot.execute_sql('SELECT 1')
for row in results:
print(row)
Expected
An error indicating my instance doesn't exist.
Actual
google.api_core.exceptions.InvalidArgument: 400 Invalid CreateSession request.
File "/usr/local/google/home/donghuiz/.local/lib/python2.7/site-packages/google/cloud/spanner_v1/database.py", line 499, in __enter__
session = self._session = self._database._pool.get()
File "/usr/local/google/home/donghuiz/.local/lib/python2.7/site-packages/google/cloud/spanner_v1/pool.py", line 268, in get
session.create()
File "/usr/local/google/home/donghuiz/.local/lib/python2.7/site-packages/google/cloud/spanner_v1/session.py", line 116, in create
session_pb = api.create_session(self._database.name, metadata=metadata, **kw)
File "/usr/local/google/home/donghuiz/.local/lib/python2.7/site-packages/google/cloud/spanner_v1/gapic/spanner_client.py", line 290, in create_session
request, retry=retry, timeout=timeout, metadata=metadata
File "/usr/local/google/home/donghuiz/.local/lib/python2.7/site-packages/google/api_core/gapic_v1/method.py", line 143, in __call__
return wrapped_func(*args, **kwargs)
File "/usr/local/google/home/donghuiz/.local/lib/python2.7/site-packages/google/api_core/retry.py", line 273, in retry_wrapped_func
on_error=on_error,
File "/usr/local/google/home/donghuiz/.local/lib/python2.7/site-packages/google/api_core/retry.py", line 182, in retry_target
return target()
File "/usr/local/google/home/donghuiz/.local/lib/python2.7/site-packages/google/api_core/timeout.py", line 214, in func_with_timeout
return func(*args, **kwargs)
File "/usr/local/google/home/donghuiz/.local/lib/python2.7/site-packages/google/api_core/grpc_helpers.py", line 59, in error_remapped_callable
six.raise_from(exceptions.from_grpc_error(exc), exc)
File "/usr/lib/python2.7/dist-packages/six.py", line 737, in raise_from
raise value
google.api_core.exceptions.InvalidArgument: 400 Invalid CreateSession request.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api: spannerIssues related to the Spanner API.Issues related to the Spanner API.backendexternalThis issue is blocked on a bug with the actual product.This issue is blocked on a bug with the actual product.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Activity
tseaver commentedon Jul 17, 2019
@crwilcox I'm not sure how we can fix that: is there a more useful message in the details of the exception we can surface? We don't want to implicitly generated an 'instance.get' call early to enforce instance existence.
mf2199 commentedon Jul 18, 2019
A simple check whether the instance exists results in another error:
InvalidArgument: 400 Invalid GetInstance request.This shouldn't happen, as
Instance.exists()method is supposed to simply return False if the instance does not exists. Instead, it throws an exception. Could it be a matter for another issue?tseaver commentedon Jul 19, 2019
@mf2199 I can't reproduce that with a "legal" instance ID:
Hyphens are allowed in instance names, but underscores are not, per the
Instancemessage API docs.mf2199 commentedon Jul 25, 2019
@tseaver Got it, thanks! The issue can be circumvented by adding some checkpoints inside the Database class'
batch()andsnapshot()methods. However, as was noted in #220, this can also be readdressed as a feature request and solved at the server side. What do you think?tseaver commentedon Jul 26, 2019
Making an unasked-for API call to validate existence of the instance / database before returning a session has undesirable performance / billing consequences.
Trying to reproduce with a valid (hyphens, not underscores) but non-existent instance id:
Which seems like a pretty helpful messsage. I think making the message for and invalid instance ID more useful is an issue for the back-end API, not for
google-cloud-spanner. It is true for other RPCs, as well, e.g.:mf2199 commentedon Jul 26, 2019
@tseaver, I suspected so, thanks for the informative response. I'd suggest this issue be redirected to the back-end team(s), given all the above argumentation.
tseaver commentedon Jul 29, 2019
@crwilcox Can you raise the issue of the error messages for invalid (not missing) instance IDs to the Spanner team?