Skip to content

Commit

Permalink
fix: fix to reload table when checking if table exists (#1002)
Browse files Browse the repository at this point in the history
* fix: fix to reload table

* changes

* lint
  • Loading branch information
asthamohta committed Aug 17, 2023
1 parent 5d91a28 commit 53bda62
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions google/cloud/spanner_v1/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ def _exists(self, snapshot):
:rtype: bool
:returns: True if the table exists, else false.
"""
if (
self._database.database_dialect
== DatabaseDialect.DATABASE_DIALECT_UNSPECIFIED
):
self._database.reload()
if self._database.database_dialect == DatabaseDialect.POSTGRESQL:
results = snapshot.execute_sql(
_EXISTS_TEMPLATE.format("WHERE TABLE_NAME = $1"),
Expand Down
10 changes: 10 additions & 0 deletions tests/system/test_table_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ def test_table_exists_not_found(shared_database):
assert not table.exists()


def test_table_exists_reload_database_dialect(
shared_instance, shared_database, not_emulator
):
database = shared_instance.database(shared_database.database_id)
assert database.database_dialect == DatabaseDialect.DATABASE_DIALECT_UNSPECIFIED
table = database.table("all_types")
assert table.exists()
assert database.database_dialect != DatabaseDialect.DATABASE_DIALECT_UNSPECIFIED


def test_db_list_tables(shared_database):
tables = shared_database.list_tables()
table_ids = set(table.table_id for table in tables)
Expand Down

0 comments on commit 53bda62

Please sign in to comment.