Skip to content

Commit 53bda62

Browse files
authored
fix: fix to reload table when checking if table exists (#1002)
* fix: fix to reload table * changes * lint
1 parent 5d91a28 commit 53bda62

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

google/cloud/spanner_v1/table.py

+5
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ def _exists(self, snapshot):
7777
:rtype: bool
7878
:returns: True if the table exists, else false.
7979
"""
80+
if (
81+
self._database.database_dialect
82+
== DatabaseDialect.DATABASE_DIALECT_UNSPECIFIED
83+
):
84+
self._database.reload()
8085
if self._database.database_dialect == DatabaseDialect.POSTGRESQL:
8186
results = snapshot.execute_sql(
8287
_EXISTS_TEMPLATE.format("WHERE TABLE_NAME = $1"),

tests/system/test_table_api.py

+10
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ def test_table_exists_not_found(shared_database):
2929
assert not table.exists()
3030

3131

32+
def test_table_exists_reload_database_dialect(
33+
shared_instance, shared_database, not_emulator
34+
):
35+
database = shared_instance.database(shared_database.database_id)
36+
assert database.database_dialect == DatabaseDialect.DATABASE_DIALECT_UNSPECIFIED
37+
table = database.table("all_types")
38+
assert table.exists()
39+
assert database.database_dialect != DatabaseDialect.DATABASE_DIALECT_UNSPECIFIED
40+
41+
3242
def test_db_list_tables(shared_database):
3343
tables = shared_database.list_tables()
3444
table_ids = set(table.table_id for table in tables)

0 commit comments

Comments
 (0)