Skip to content

(fix) cqltypes: fix SyntaxWarning for invalid escape sequence in UDT names#750

Open
mykaul wants to merge 1 commit intoscylladb:masterfrom
mykaul:fix/cqltypes-strip-frozen-escape-warning
Open

(fix) cqltypes: fix SyntaxWarning for invalid escape sequence in UDT names#750
mykaul wants to merge 1 commit intoscylladb:masterfrom
mykaul:fix/cqltypes-strip-frozen-escape-warning

Conversation

@mykaul
Copy link

@mykaul mykaul commented Mar 14, 2026

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

  • I have split my patch into logically separate commits.
  • All commit messages clearly explain what they change and why.
  • [] I added relevant tests for new features and bug fixes.
  • All commits compile, pass static checks and pass test.
  • PR description sums up the changes and reasons why they should be introduced.
  • I have provided docstrings for the public items that I want to introduce.
  • I have adjusted the documentation in ./docs/source/.
  • I added appropriate Fixes: annotations to PR description.

@mykaul mykaul force-pushed the fix/cqltypes-strip-frozen-escape-warning branch from c8797af to c3b8f16 Compare March 14, 2026 21:53
@mykaul mykaul requested a review from Copilot March 15, 2026 15:40
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 emit SyntaxWarning and that python_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.
@mykaul mykaul force-pushed the fix/cqltypes-strip-frozen-escape-warning branch from c3b8f16 to 91cdd32 Compare March 16, 2026 18:02
@mykaul mykaul requested a review from Copilot March 16, 2026 18:03
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 avoid SyntaxWarning/parsing issues during ast.literal_eval.
  • Unescape \' in python_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 mykaul self-assigned this Mar 16, 2026
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