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

SqliteHook invalid insert syntax #17632

Closed
Bart-art opened this issue Aug 16, 2021 · 4 comments · Fixed by #17695
Closed

SqliteHook invalid insert syntax #17632

Bart-art opened this issue Aug 16, 2021 · 4 comments · Fixed by #17695
Assignees
Labels
good first issue kind:bug This is a clearly a bug

Comments

@Bart-art
Copy link

Apache Airflow version: 2.1.0

OS: Raspbian GNU/Linux 10 (buster)

Apache Airflow Provider versions: apache-airflow-providers-sqlite==1.0.2

Deployment: Virtualenv

What happened:

When using the insert_rows function of the sqlite hook the generated parametrized sql query has an invalid syntax. It will generate queries with the %s placeholder which result in the following error:

Query: INSERT INTO example_table (col1, col2) VALUES (%s,%s)

Error:
sqlite3.OperationalError: near "%": syntax error

Stacktrace:
File "/home/airflow/.pyenv/versions/3.8.10/envs/airflow_3.8.10/lib/python3.8/site-packages/airflow/hooks/dbapi.py", line 307, in insert_rows
cur.execute(sql, values)

I replaced the placeholder with "?" in the _generate_insert_sql function DbApiHook as a test. This solved the issue.

What you expected to happen:

Every inherited method of the DbApiHook should work for the SqliteHook. Using the insert_rows method should generate the correct parametrized query and insert rows as expected.

How to reproduce it:

  1. Create an instance of the SqliteHook
  2. Use the insert_rows method of the SqliteHook
@Bart-art Bart-art added the kind:bug This is a clearly a bug label Aug 16, 2021
@boring-cyborg
Copy link

boring-cyborg bot commented Aug 16, 2021

Thanks for opening your first issue here! Be sure to follow the issue template!

@potiuk
Copy link
Member

potiuk commented Aug 16, 2021

Would you be willing to provide a fix for that @Bart-art ? That sounds like rather easy fix - good for first-time contribution. Happy to help with it if needed.

@subkanthi
Copy link
Contributor

@Bart-art if you are not working on it, please let me know I can also take it on.

@potiuk
Copy link
Member

potiuk commented Aug 17, 2021

Assigned you @subkanthi -> @Bart-art if you want you can join as well (at least as reviewer :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue kind:bug This is a clearly a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants