(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 intoscylladb:masterfrom
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.
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.
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.
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.