fix: prevent SQL keyword parameterization in MySQL bulk_load_custom - #63530
Merged
potiuk merged 6 commits intoApr 6, 2026
Merged
Conversation
The bulk_load_custom method was incorrectly passing duplicate_key_handling and extra_options as parameterized values to cursor.execute(). MySQL drivers treat parameterized values as data and quote them as string literals, producing invalid SQL like: LOAD DATA LOCAL INFILE '/tmp/file' 'IGNORE' INTO TABLE `table` 'FIELDS...' This was introduced in PR apache#33328 which changed from string concatenation to parameterization. However, duplicate_key_handling (IGNORE/REPLACE) and extra_options are SQL syntax keywords, not data values. Fixed by interpolating these keywords directly into the SQL statement via f-string while keeping tmp_file as the sole parameterized value: LOAD DATA LOCAL INFILE %s IGNORE INTO TABLE `table` FIELDS... Updated existing tests and added parametrized test to verify both IGNORE and REPLACE keywords appear literally in SQL without being parameterized. Closes: apache#62506 Signed-off-by: majiayu000 <1835304752@qq.com>
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
|
2 tasks
SameerMesiah97
left a comment
Contributor
There was a problem hiding this comment.
Fix CI and possibly a minor spacing issue and this should be good enough to merge.
Signed-off-by: majiayu000 <1835304752@qq.com>
Signed-off-by: majiayu000 <1835304752@qq.com>
Signed-off-by: majiayu000 <1835304752@qq.com>
potiuk
approved these changes
Apr 6, 2026
|
Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions. |
shivaam
pushed a commit
to shivaam/airflow
that referenced
this pull request
Apr 8, 2026
…pache#63530) * fix: prevent SQL keyword parameterization in MySQL bulk_load_custom The bulk_load_custom method was incorrectly passing duplicate_key_handling and extra_options as parameterized values to cursor.execute(). MySQL drivers treat parameterized values as data and quote them as string literals, producing invalid SQL like: LOAD DATA LOCAL INFILE '/tmp/file' 'IGNORE' INTO TABLE `table` 'FIELDS...' This was introduced in PR apache#33328 which changed from string concatenation to parameterization. However, duplicate_key_handling (IGNORE/REPLACE) and extra_options are SQL syntax keywords, not data values. Fixed by interpolating these keywords directly into the SQL statement via f-string while keeping tmp_file as the sole parameterized value: LOAD DATA LOCAL INFILE %s IGNORE INTO TABLE `table` FIELDS... Updated existing tests and added parametrized test to verify both IGNORE and REPLACE keywords appear literally in SQL without being parameterized. Closes: apache#62506 Signed-off-by: majiayu000 <1835304752@qq.com> * fix: address review feedback on test formatting and spacing Signed-off-by: majiayu000 <1835304752@qq.com> * fix: clean up spacing in bulk_load_custom test assertion Signed-off-by: majiayu000 <1835304752@qq.com> * fix: apply ruff format to mysql.py for CI compliance Signed-off-by: majiayu000 <1835304752@qq.com> --------- Signed-off-by: majiayu000 <1835304752@qq.com> Co-authored-by: Jarek Potiuk <jarek@potiuk.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes incorrect SQL keyword parameterization in
MySqlHook.bulk_load_custom()that causes MySQL drivers to quoteIGNORE/REPLACEkeywords as string literals, producing invalid SQL.Problem
bulk_load_custom()passesduplicate_key_handling(e.g.,IGNORE,REPLACE) andextra_optionsas parameterized query values viacursor.execute(sql, parameters). The MySQL driver treats parameterized values as data and quotes them as string literals, producing invalid SQL like:This was introduced in PR #33328 which changed from string concatenation to parameterization for these keywords.
Root Cause
In
providers/mysql/src/airflow/providers/mysql/hooks/mysql.py, thebulk_load_custommethod builds the SQL as:Both
duplicate_key_handlingandextra_optionsare SQL syntax keywords, not data values. Onlytmp_fileis actual data that should be parameterized.Fix
Changed
bulk_load_customto interpolateduplicate_key_handlingandextra_optionsdirectly into the SQL statement via f-string, while keepingtmp_fileas the sole parameterized value:Updated existing tests (
test_bulk_load_custom,test_bulk_load_custom_hook_lineage) to assert the new SQL shape and parameter tuple. Added a new parametrized testtest_bulk_load_custom_duplicate_key_not_parameterizedthat validates bothIGNOREandREPLACEappear literally in the executed SQL and onlytmp_fileis parameterized.closes: #62506
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Opus 4.6 following the guidelines