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

[bugfix] Correctly quote table and schema in select_star #8181

Merged
merged 4 commits into from
Sep 5, 2019
Merged
Changes from 1 commit
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
22 changes: 22 additions & 0 deletions tests/model_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,28 @@ def test_select_star(self):
)
assert sql.startswith(expected)

def test_select_star_with_exotic_names(self):
main_db = get_example_database()
Copy link
Member

Choose a reason for hiding this comment

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

@villebro I'm not overly familiar with the new example database but I gather the engine is related to the tox environment, i.e., py36-mysql, py35-sqlite, etc.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's my understanding that the example db falls back to SQLALCHEMY_DATABASE_URI if SQLALCHEMY_EXAMPLES_URI is undefined, i.e. it should test all engines that have a tox env.

schema = "schema.name"
table_name = "table/name"
sql = main_db.select_star(
table_name, schema=schema, show_cols=False, latest_partition=False
)
fully_qualified_names = {
"sqlite": '"schema.name"."table/name"',
"mysql": "`schema.name`.`table/name`",
"postgres": '"schema.name"."table/name"',
}
fully_qualified_name = fully_qualified_names.get(main_db.db_engine_spec.engine)
if fully_qualified_name:
expected = textwrap.dedent(
f"""\
SELECT *
FROM {fully_qualified_name}
LIMIT 100"""
)
assert sql.startswith(expected)

def test_single_statement(self):
main_db = get_main_database()

Expand Down