(fix) cqltypes: fix SyntaxWarning for invalid escape sequence in UDT names - #750
(fix) cqltypes: fix SyntaxWarning for invalid escape sequence in UDT names#750mykaul wants to merge 1 commit into
Conversation
c8797af to
c3b8f16
Compare
There was a problem hiding this comment.
Pull request overview
This PR hardens the CQL type parsing utilities to avoid SyntaxWarning when parsing escaped CQL identifiers that contain backslashes, and adds a regression test to ensure the warning does not recur.
Changes:
- Escape backslashes when converting escaped, double-quoted CQL tokens into a Python literal for
ast.literal_eval(). - Add a unit test that asserts
cqltype_to_python()does not emitSyntaxWarningand thatpython_to_cqltype()round-trips the parsed structure.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
cassandra/cqltypes.py |
Escapes backslashes in escaped-quoted identifier tokens before ast.literal_eval() to prevent invalid-escape SyntaxWarning. |
tests/unit/test_metadata.py |
Adds a regression test covering backslash-containing escaped identifiers and round-trip behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
c3b8f16 to
91cdd32
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates the CQL type string <-> Python representation conversion helpers to correctly handle quoted identifiers containing backslashes and single quotes, and adds unit tests to prevent regressions.
Changes:
- Escape backslashes and single quotes in
cqltype_to_python()to avoidSyntaxWarning/parsing issues duringast.literal_eval. - Unescape
\'inpython_to_cqltype()to support round-tripping identifiers containing'. - Add unit tests covering backslash-containing identifiers (no
SyntaxWarning) and single-quote-containing identifiers (parse + round-trip).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
cassandra/cqltypes.py |
Adjusts escaping/unescaping in cqltype_to_python and python_to_cqltype for quoted identifiers. |
tests/unit/test_metadata.py |
Adds regression tests for backslash/single-quote handling and round-trip behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@mykaul This is not a draft, but review was not requested. Please either change to draft, or request review. |
@Lorak-mmk - who should I ask to review it? |
91cdd32 to
d42c4f1
Compare
|
Warning Review limit reachedNext included review available in 59 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: QUIET Plan: Advanced Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughCQL type conversion now escapes backslashes and single quotes when converting quoted tokens into Python literals. Reverse conversion unescapes escaped single quotes alongside backslashes. Metadata tests cover round-trip behavior for UDT identifiers containing backslashes and single quotes, including verification that backslash parsing emits no Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Rebased onto current Verification performed:
Force-pushed the rebase; no code changes were needed beyond the rebase itself. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
cassandra/cqltypes.py:159
- Reverse the quote escape before collapsing doubled backslashes. With the current order, a valid identifier containing a backslash immediately before an apostrophe (for example
map<"a\'b", int>) loses that backslash during a round trip: the first replacement shortens the encoded backslash run, and the second then consumes the remaining backslash as the apostrophe escape.
cql = ''.join(scanned_tokens).replace('\\\\', '\\').replace("\\'", "'")
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/unit/test_metadata.py (1)
851-885: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd coverage for identifiers with multiple apostrophes.
The current single-quote test does not force
repr(types)to change quote styles. Add a regression such asmap<"a'b'c'd", int>and a mixed backslash/apostrophe case to cover the reverse-conversion boundary.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/unit/test_metadata.py` around lines 851 - 885, Extend test_cqltype_single_quote_in_identifier with an identifier containing multiple apostrophes, such as map<"a'b'c'd", int>, and assert parsing plus round-trip preservation. Add a separate mixed backslash/apostrophe regression case to exercise the python_to_cqltype reverse-conversion boundary, retaining the existing result-structure and round-trip assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tests/unit/test_metadata.py`:
- Around line 851-885: Extend test_cqltype_single_quote_in_identifier with an
identifier containing multiple apostrophes, such as map<"a'b'c'd", int>, and
assert parsing plus round-trip preservation. Add a separate mixed
backslash/apostrophe regression case to exercise the python_to_cqltype
reverse-conversion boundary, retaining the existing result-structure and
round-trip assertions.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 448070d7-6690-4edd-ae0a-ad5dcc294143
📒 Files selected for processing (2)
cassandra/cqltypes.pytests/unit/test_metadata.py
In cqltype_to_python(), double-quoted UDT names containing backslashes or single quotes were passed to ast.literal_eval without proper escaping, producing SyntaxWarning on Python 3.12+ or SyntaxError for single quotes. Escape both backslashes and single quotes before wrapping the token for ast.literal_eval. The reverse operation in python_to_cqltype() is updated to unescape both sequences as well.
d42c4f1 to
4cd9462
Compare
In cqltype_to_python(), double-quoted UDT names containing backslashes (e.g. '"!@#$%^&*()[]\ frozen >>>") were passed to ast.literal_eval without escaping, producing SyntaxWarning on Python 3.12+:
SyntaxWarning: "\ " is an invalid escape sequence
Escape backslashes before wrapping the token for ast.literal_eval. The reverse operation already exists in python_to_cqltype() at line 159.
Pre-review checklist
./docs/source/.Fixes:annotations to PR description.