8000 fix: use empty schema name by default by IlyaFaer · Pull Request #32 · googleapis/python-spanner-sqlalchemy · GitHub
[go: up one dir, main page]

Skip to content

fix: use empty schema name by default #32

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

Merged
merged 14 commits into from
Apr 6, 2021
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
2 changes: 1 addition & 1 deletion google/cloud/sqlalchemy_spanner/sqlalchemy_spanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ def get_table_names(self, connection, schema=None, **kw):
FROM information_schema.tables
WHERE table_schema = '{}'
""".format(
schema
schema or ""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default schema arg is None, so it tried to search for tables with schema 'None'. Not sure how I've written this, it's not smart at all. Fixing it.

)

table_names = []
Expand Down
45 changes: 45 additions & 0 deletions test/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,3 +682,48 @@ def test_unique_constraint_raises(self):

with pytest.raises(spanner_dbapi.exceptions.ProgrammingError):
self.metadata.create_all()

@testing.provide_metadata
def _test_get_table_names(self, schema=None, table_type="table", order_by=None):
"""
SPANNER OVERRIDE:

Spanner doesn't support temporary tables, so real tables are
used for testing. As the original test expects only real
tables to be read, and in Spanner all the tables are real,
expected results override is required.
"""
_ignore_tables = [
"comment_test",
"noncol_idx_test_pk",
"noncol_idx_test_nopk",
"local_table",
"remote_table",
"remote_table_2",
]
meta = self.metadata

insp = inspect(meta.bind)

if table_type == "view":
table_names = insp.get_view_names(schema)
table_names.sort()
answer = ["email_addresses_v", "users_v"]
eq_(sorted(table_names), answer)
else:
if order_by:
tables = [
rec[0]
for rec in insp.get_sorted_table_and_fkc_names(schema)
if rec[0]
]
else:
tables = insp.get_table_names(schema)
table_names = [t for t in tables if t not in _ignore_tables]

if order_by == "foreign_key":
answer = ["users", "user_tmp", "email_addresses", "dingalings"]
eq_(table_names, answer)
else:
answer = ["dingalings", "email_addresses", "user_tmp", "users"]
Copy link
Contributor Author
@IlyaFaer IlyaFaer Mar 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

user_tmp is a temporary table, adding it into the expected results

eq_(sorted(table_names), answer)
0