Cloud Spanner client incorrectly handles NOT_FOUND error returned by create database
While creating a database, is the backend returns NOT_FOUND error, the client assumes it to indicate that instance is not found and thus returns "Instance not found" error message:
https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/spanner/google/cloud/spanner_v1/database.py#L213
This is not always the case as cloud spanner can return NOT_FOUND in other scenarios. For eg in the "CREATE INDEX ... " ddl statement that table that the index is being created on does not exist it would return a NOT_FOUND. I think the fix would be to just pass the error message returned by the rpc to the user.
This can be reproduced using:
from google.cloud import spanner """Creates a database and tables for pattern 1 sample data.""" spanner_client = spanner.Client() instance = spanner_client.instance("test-instance") database = instance.database("bitemporal_pattern1", ddl_statements=[ """CREATE TABLE MyTable ( Id String(36) NOT NULL, Field1 STRING(36) NOT NULL ) PRIMARY KEY (Id)""" , """CREATE INDEX IDX ON yTable (Field1)""" ]) operation = database.create() print('Waiting for operation to complete...') operation.result()