Skip to content

Commit fc96009

Browse files
committed
Spanner: Fix database not found error, Closes googleapis#4071
1 parent 0dbccac commit fc96009

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

spanner/google/cloud/spanner_v1/database.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ def create(self):
211211
if exc_to_code(exc.cause) == StatusCode.ALREADY_EXISTS:
212212
raise Conflict(self.name)
213213
elif exc_to_code(exc.cause) == StatusCode.NOT_FOUND:
214-
raise NotFound('Instance not found: {name}'.format(
215-
name=self._instance.name,
214+
raise NotFound('Database not found: {name}'.format(
215+
name=db_name,
216216
))
217217
raise
218218

spanner/tests/system/test_system.py

+13
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
from google.cloud._helpers import UTC
3838
from google.cloud.exceptions import GrpcRendezvous
39+
from google.cloud.exceptions import NotFound
3940
from google.cloud.spanner_v1._helpers import TimestampWithNanoseconds
4041
from google.cloud.spanner import Client
4142
from google.cloud.spanner import KeyRange
@@ -282,6 +283,18 @@ def test_create_database(self):
282283
for database in Config.INSTANCE.list_databases()]
283284
self.assertIn(temp_db_id, database_ids)
284285

286+
def test_create_database_not_found(self):
287+
temp_db_id = 'temp_db' + unique_resource_id('_')
288+
temp_db = Config.INSTANCE.database("bitemporal_pattern1", ddl_statements=[
289+
"""CREATE TABLE MyTable (
290+
Id String(36) NOT NULL,
291+
Field1 STRING(36) NOT NULL
292+
) PRIMARY KEY (Id)""",
293+
"""CREATE INDEX IDX ON yTable (Field1)"""
294+
])
295+
with self.assertRaisesRegexp(NotFound, "Database not found"):
296+
operation = temp_db.create()
297+
285298
def test_update_database_ddl(self):
286299
pool = BurstyPool()
287300
temp_db_id = 'temp_db' + unique_resource_id('_')

0 commit comments

Comments
 (0)