Skip to content

Don't flag a safe UPDATE as destructive when it starts with a comment - #2440

Merged
rolandwalker merged 1 commit into
dbcli:mainfrom
Kernel-Hunter:fix-destructive-leading-comment
Nov 16, 2026
Merged

rolandwalker merged 1 commit into
dbcli:mainfrom
Kernel-Hunter:fix-destructive-leading-comment

Conversation

@Kernel-Hunter

Copy link
Copy Markdown
Contributor

Description

With destructive_warning including update, this asks for confirmation:

/* c */ UPDATE t SET a = 1 WHERE id = 1;

while the same statement without the comment, or with the comment written as /* c */UPDATE or -- c on its own line, runs without a prompt.

query_is_single_table_update() runs sqlparse.format(query, strip_comments=True) first. For a leading block comment followed by a space that leaves " UPDATE t SET ...", so statement[0] is the whitespace token and the function returns False. I strip the cleaned query before parsing.

I added the leading-comment case to test_query_is_single_table_update and a new test_is_destructive_update_with_where_clause_and_leading_comment. Both fail on main and pass with the fix; test_sql_utils.py (176 tests) and the execute/batch/interactive_utils tests pass.

Checklist

  • I added this contribution to the changelog.md file.
  • I added my name to the mycli/AUTHORS.txt file (or it's already there).
  • To lint and format the code, I ran
    uv run ruff check && uv run ruff format && uv run mypy --install-types .

sqlparse's strip_comments leaves the space after a leading /* ... */
comment, so the first token of the cleaned query was whitespace and
query_is_single_table_update() returned False.
@rolandwalker

Copy link
Copy Markdown
Contributor

Nice catch! Thanks!

@rolandwalker
rolandwalker merged commit 16a8d94 into dbcli:main Nov 16, 2026
23 of 24 checks passed
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

Successfully merging this pull request may close these issues.

2 participants