Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix to reload table when checking if table exists #1002

Merged
merged 3 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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