Skip to content

Commit

Permalink
Spanner: Fix database not found error, Closes #4071
Browse files Browse the repository at this point in the history
  • Loading branch information
chemelnucfin committed Dec 8, 2017
1 parent 0dbccac commit fc96009
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions spanner/google/cloud/spanner_v1/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ def create(self):
if exc_to_code(exc.cause) == StatusCode.ALREADY_EXISTS:
raise Conflict(self.name)
elif exc_to_code(exc.cause) == StatusCode.NOT_FOUND:
raise NotFound('Instance not found: {name}'.format(
name=self._instance.name,
raise NotFound('Database not found: {name}'.format(
name=db_name,
))
raise

Expand Down
13 changes: 13 additions & 0 deletions spanner/tests/system/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

from google.cloud._helpers import UTC
from google.cloud.exceptions import GrpcRendezvous
from google.cloud.exceptions import NotFound
from google.cloud.spanner_v1._helpers import TimestampWithNanoseconds
from google.cloud.spanner import Client
from google.cloud.spanner import KeyRange
Expand Down Expand Up @@ -282,6 +283,18 @@ def test_create_database(self):
for database in Config.INSTANCE.list_databases()]
self.assertIn(temp_db_id, database_ids)

def test_create_database_not_found(self):
temp_db_id = 'temp_db' + unique_resource_id('_')
temp_db = Config.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)"""
])
with self.assertRaisesRegexp(NotFound, "Database not found"):
operation = temp_db.create()

def test_update_database_ddl(self):
pool = BurstyPool()
temp_db_id = 'temp_db' + unique_resource_id('_')
Expand Down

0 comments on commit fc96009

Please sign in to comment.