Recognize ROW_FORMAT as a keyword (issue773)#860
Open
apoorvdarshan wants to merge 1 commit into
Open
Conversation
`ALTER TABLE mytable ROW_FORMAT=Dynamic` parsed the table name and the option as a single identifier (`mytable ROW_FORMAT`), because ROW_FORMAT was tokenized as a Name and treated as an alias of the table. ENGINE, AUTO_INCREMENT and similar table options are already keywords, so `ALTER TABLE mytable ENGINE=InnoDB` parses correctly. Add ROW_FORMAT to the KEYWORDS dict for consistent behavior, and add a regression test.
There was a problem hiding this comment.
Pull request overview
This pull request fixes a MySQL-specific parsing regression where ROW_FORMAT in ALTER TABLE ... ROW_FORMAT=... was tokenized as a Name, causing the table name and option to be grouped into a single identifier. It does so by recognizing ROW_FORMAT as a keyword and adds a regression test and changelog entry to lock in the behavior.
Changes:
- Add
ROW_FORMATto the keyword set so it’s tokenized asKeywordrather thanName. - Add a regression test ensuring
ROW_FORMATis not absorbed as a table alias inALTER TABLE. - Document the fix in the
CHANGELOG.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/test_regressions.py | Adds a regression test covering ALTER TABLE ... ROW_FORMAT=... tokenization and identifier grouping. |
| sqlparse/keywords.py | Registers ROW_FORMAT as a Keyword to prevent incorrect identifier alias grouping. |
| CHANGELOG | Notes the bug fix for issue #773. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+460
to
+462
| p = sqlparse.parse('ALTER TABLE mytable ROW_FORMAT=Dynamic')[0] | ||
| row_format = p.token_next_by(m=(T.Keyword, 'ROW_FORMAT'))[1] | ||
| assert row_format is not None |
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 #773.
Problem
ALTER TABLE mytable ROW_FORMAT=Dynamicparses the table name and the option together as a single identifier:ROW_FORMATwas tokenized as aName, so the identifier grouper treated it as an alias ofmytable(mytable ROW_FORMAT).Fix
ENGINE,AUTO_INCREMENTand similar table options are already listed inKEYWORDS, which is whyALTER TABLE mytable ENGINE=InnoDBparses correctly (the table name is a standalone identifier). This addsROW_FORMATtoKEYWORDSfor consistent behavior:Verification
test_alter_table_row_format_issue773totests/test_regressions.py; it fails onmain(noROW_FORMATkeyword) and passes with this change.488 passed, 2 xfailed, 1 xpassed(thexpassedis pre-existing and identical onmain); no regressions.ruff check sqlparse/(the CI lint command) is clean.CHANGELOGentry.Disclosure: this change was prepared with the assistance of an AI tool (Claude Code). I reproduced the issue, reviewed and verified the fix and test results, and take responsibility for the contribution and will respond to review feedback personally.