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

Format characters in SQL comments raises error with SQLAlchemy connection #425

Open
derek-pyne opened this issue Feb 3, 2022 · 0 comments

Comments

@derek-pyne
Copy link

Context:
Pandas read_sql is now raising a warning suggesting moving from a DB-API connection to a SQLAlchemy connection. Hence we are trying to make the switch.

Issue:
When using a SQLAlchemy connection, if the query has any format characters in it, then an error is raised. No issue with a DB-API connection.

Example query:

-- Format character in a comment %
SELECT 1

Likely Cause
When deciding whether to format the operation, PyHive checks if the given parameters is None.

if parameters is None:

However, SQLAlchemy (1.4.31) always at least passes an empty dictionary (since it builds these params off of kwargs which default to an empty dict) so it is never None.

https://github.com/sqlalchemy/sqlalchemy/blob/2eac6545ad08db83954dd3afebf4894a0acb0cea/lib/sqlalchemy/engine/base.py#L1196

Likely Fix
Just need to also check if params is an empty dict:

if params is None or not params:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant