Skip to content

fix: pick a quote the query does not contain - #263

Merged
rayakame merged 1 commit into
mainfrom
fix/quote-safe-sql-constants
Aug 16, 2026
Merged

fix: pick a quote the query does not contain#263
rayakame merged 1 commit into
mainfrom
fix/quote-safe-sql-constants

Conversation

@rayakame

Copy link
Copy Markdown
Owner

Fixes #261.

Three consecutive double quotes in a query - from a string literal, or a quoted identifier ending in a quote - closed the constant early and left the rest of the module as stray syntax. The file did not parse at all.

The constant and the docstring now pick their delimiter from the text: """ unless the query holds it, ''' otherwise. A query holding both has no block spelling left, so the constant falls back to an escaped one-liner - it still carries the SQL exactly, it just stops looking like it. The docstring cannot follow, since escaping one trips ruff D301 whatever the backslash spells, so it leaves the SQL out and the constant keeps it.

Fixture in driver_sqlite3 covering both shapes, with runtime assertions on the values that come back. Existing fixtures are untouched: a query without a quote run still gets the plain """.

Three consecutive double quotes in a query - from a string literal, or a
quoted identifier ending in a quote - closed the constant early and left
the rest of the module as stray syntax. The file did not parse.

The constant and the docstring now choose their delimiter from the text:
""" unless the query holds it, ''' otherwise. A query holding both has no
block spelling left, so the constant falls back to an escaped one-liner,
which carries the SQL exactly and only stops looking like it. The
docstring cannot follow: escaping a docstring trips ruff D301 whatever
the backslash spells, so it leaves the SQL out and the constant keeps it.

Closes #261
@codecov

codecov Bot commented Aug 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@rayakame

Copy link
Copy Markdown
Owner Author

@coderabbitai full-review

@coderabbitai

coderabbitai Bot commented Aug 16, 2026

Copy link
Copy Markdown

@rayakame I will perform a complete review of #263, including the quote-delimiter logic and the new fixtures.

✅ Action performed

Full review finished.

@coderabbitai

coderabbitai Bot commented Aug 16, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: b9749f23-f344-41cc-839b-c70f4685930d

📥 Commits

Reviewing files that changed from the base of the PR and between bbbdb9d and a7cd8ca.

⛔ Files ignored due to path filters (10)
  • test/driver_aiosqlite/sqlc-gen-better-python.wasm is excluded by !**/*.wasm, !**/*.wasm
  • test/driver_asyncmy/sqlc-gen-better-python.wasm is excluded by !**/*.wasm, !**/*.wasm
  • test/driver_asyncpg/sqlc-gen-better-python.wasm is excluded by !**/*.wasm, !**/*.wasm
  • test/driver_psycopg_async/sqlc-gen-better-python.wasm is excluded by !**/*.wasm, !**/*.wasm
  • test/driver_psycopg_sync/sqlc-gen-better-python.wasm is excluded by !**/*.wasm, !**/*.wasm
  • test/driver_pymysql/sqlc-gen-better-python.wasm is excluded by !**/*.wasm, !**/*.wasm
  • test/driver_sqlite3/dataclass/functions/queries_triple_quote.py is excluded by !test/driver_*/*/functions/**
  • test/driver_sqlite3/sqlc-gen-better-python.wasm is excluded by !**/*.wasm, !**/*.wasm
  • test/driver_turso_async/sqlc-gen-better-python.wasm is excluded by !**/*.wasm, !**/*.wasm
  • test/driver_turso_sync/sqlc-gen-better-python.wasm is excluded by !**/*.wasm, !**/*.wasm
📒 Files selected for processing (19)
  • .changes/unreleased/Fixed-20260816-140000.yaml
  • internal/render/queries.go
  • internal/render/render_queries_test.go
  • internal/writer/docstrings.go
  • internal/writer/docstrings_test.go
  • internal/writer/writer.go
  • internal/writer/writer_test.go
  • sqlc.yaml
  • test/driver_aiosqlite/sqlc.yaml
  • test/driver_asyncmy/sqlc.yaml
  • test/driver_asyncpg/sqlc.yaml
  • test/driver_psycopg_async/sqlc.yaml
  • test/driver_psycopg_sync/sqlc.yaml
  • test/driver_pymysql/sqlc.yaml
  • test/driver_sqlite3/dataclass/test_sqlite3_dataclass_functions.py
  • test/driver_sqlite3/queries_triple_quote.sql
  • test/driver_sqlite3/sqlc.yaml
  • test/driver_turso_async/sqlc.yaml
  • test/driver_turso_sync/sqlc.yaml

Included review availability: 4 reviews are currently available. Based on recent review activity, included reviews refill at 5 per hour.


📝 Walkthrough

Walkthrough

The change adds delimiter-aware Python literal selection for SQL containing triple quotes or backslashes. Generated query constants select a safe delimiter or use an escaped fallback. Query docstrings select matching delimiters or omit unsupported SQL. Rendering, writer, and SQLite regression tests cover these cases. SQLC configurations update the Python plugin checksums.

Merge Risk: ⚪ Minimal · up to a7cd8

The change makes generated SQL constants and docstrings safe for queries containing triple quotes, with fixture and runtime coverage; no actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: selecting a quote delimiter absent from the query.
Description check ✅ Passed The description directly explains the triple-quote parsing failure, delimiter selection, fallback behavior, and regression fixture.
Linked Issues check ✅ Passed The changes address issue #261 by selecting safe delimiters, preserving SQL in constants, handling both delimiters, and adding regression coverage.
Out of Scope Changes check ✅ Passed The checksum updates, fixture, tests, and change note support the quote-handling fix and show no unrelated code changes.

Comment @coderabbitai help to get the list of available commands.

@rayakame
rayakame merged commit b991931 into main Aug 16, 2026
24 checks passed
@rayakame
rayakame deleted the fix/quote-safe-sql-constants branch August 16, 2026 15:56
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.

A triple quote in the SQL breaks the generated module

1 participant