File tree 2 files changed +33
-7
lines changed
2 files changed +33
-7
lines changed Original file line number Diff line number Diff line change 18
18
import threading
19
19
20
20
import google .auth .credentials
21
+ from google .api_core import exceptions
21
22
from google .gax .errors import GaxError
22
23
from google .gax .grpc import exc_to_code
23
24
from google .cloud .spanner_v1 .gapic .spanner_client import SpannerClient
@@ -208,14 +209,11 @@ def create(self):
208
209
options = options ,
209
210
)
210
211
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
- ))
212
+ exception = exceptions .from_grpc_error (exc .cause )
213
+ if (exception .grpc_status_code == StatusCode .ALREADY_EXISTS
214
+ or exception .grpc_status_code == StatusCode .NOT_FOUND ):
215
+ raise exception
217
216
raise
218
-
219
217
return future
220
218
221
219
def exists (self ):
Original file line number Diff line number Diff line change 36
36
37
37
from google .cloud ._helpers import UTC
38
38
from google .cloud .exceptions import GrpcRendezvous
39
+ from google .cloud .exceptions import NotFound
39
40
from google .cloud .spanner_v1 ._helpers import TimestampWithNanoseconds
40
41
from google .cloud .spanner import Client
41
42
from google .cloud .spanner import KeyRange
@@ -282,6 +283,33 @@ def test_create_database(self):
282
283
for database in Config .INSTANCE .list_databases ()]
283
284
self .assertIn (temp_db_id , database_ids )
284
285
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
+
285
313
def test_update_database_ddl (self ):
286
314
pool = BurstyPool ()
287
315
temp_db_id = 'temp_db' + unique_resource_id ('_' )
You can’t perform that action at this time.
0 commit comments