File tree Expand file tree Collapse file tree 2 files changed +31
-8
lines changed Expand file tree Collapse file tree 2 files changed +31
-8
lines changed Original file line number Diff line number Diff line change 1818import threading
1919
2020import google .auth .credentials
21+ from google .api_core import exceptions
2122from google .gax .errors import GaxError
2223from google .gax .grpc import exc_to_code
2324from google .cloud .spanner_v1 .gapic .spanner_client import SpannerClient
@@ -208,14 +209,8 @@ def create(self):
208209 options = options ,
209210 )
210211 except GaxError as exc :
211- if exc_to_code (exc .cause ) == StatusCode .ALREADY_EXISTS :
212- raise Conflict (self .name )
213- elif exc_to_code (exc .cause ) == StatusCode .NOT_FOUND :
214- raise NotFound ('Instance not found: {name}' .format (
215- name = self ._instance .name ,
216- ))
217- raise
218-
212+ exception = exceptions .from_grpc_error (exc .cause )
213+ raise exception
219214 return future
220215
221216 def exists (self ):
Original file line number Diff line number Diff line change 3636
3737from google .cloud ._helpers import UTC
3838from google .cloud .exceptions import GrpcRendezvous
39+ from google .cloud .exceptions import NotFound
3940from google .cloud .spanner_v1 ._helpers import TimestampWithNanoseconds
4041from google .cloud .spanner import Client
4142from google .cloud .spanner import KeyRange
@@ -282,6 +283,33 @@ 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_table_not_found (self ):
287+ temp_db_id = 'temp_db' + unique_resource_id ('_' )
288+
289+ table_name1 = 'MyTable'
290+ table_name2 = 'NotMyTable'
291+ self .assertNotEqual (table_name1 , table_name2 )
292+
293+ create_table = (
294+ 'CREATE TABLE {} (\n '
295+ ' Id STRING(36) NOT NULL,\n '
296+ ' Field1 STRING(36) NOT NULL\n '
297+ ') PRIMARY KEY (Id)' )
298+ create_table = create_table .format (table_name1 )
299+ create_index = 'CREATE INDEX IDX ON {} (Field1)' .format (table_name2 )
300+
301+ temp_db = Config .INSTANCE .database (
302+ temp_db_id ,
303+ ddl_statements = [
304+ create_table ,
305+ create_index ,
306+ ],
307+ )
308+ with self .assertRaisesRegexp (NotFound ,
309+ '404 Table not found: '
310+ + table_name2 ):
311+ temp_db .create ()
312+
285313 def test_update_database_ddl (self ):
286314 pool = BurstyPool ()
287315 temp_db_id = 'temp_db' + unique_resource_id ('_' )
You can’t perform that action at this time.
0 commit comments