Skip to content

use bound params and format_str in DDL/inspector#728

Merged
joe-clickhouse merged 3 commits intomainfrom
joe/minimal-sqa-updates
May 5, 2026
Merged

use bound params and format_str in DDL/inspector#728
joe-clickhouse merged 3 commits intomainfrom
joe/minimal-sqa-updates

Conversation

@joe-clickhouse
Copy link
Copy Markdown
Contributor

Summary

This is a re-implementation of the suggestions from #711.

  • switch the system.tables lookup from f-string interpolation to SQLA bound parameters
  • build the engine arguments with the existing format_str helper instead of raw f-string interpolation, and fix a missing closing ) that made the original Replicated DDL emit invalid SQL

Checklist

Delete items not relevant to your PR:

  • Unit and integration tests covering the common scenarios were added
  • A human-readable description of the changes was provided to include in CHANGELOG
  • For significant changes, documentation in https://github.com/ClickHouse/clickhouse-docs was updated with further explanations or tutorials

Copy link
Copy Markdown
Contributor

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 SQLAlchemy integration by removing raw string interpolation in reflection/DDL paths, using SQLAlchemy bound parameters and the project’s format_str escaping helper, and fixes invalid Replicated CREATE DATABASE DDL output.

Changes:

  • Replace system.tables engine lookup string interpolation with a bound-parameter query.
  • Build Replicated database engine arguments using format_str and add the missing closing ) in emitted DDL.
  • Add unit tests covering CreateDatabase/DropDatabase DDL generation (including escaping).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
clickhouse_connect/cc_sqlalchemy/inspector.py Switches system.tables lookup to a parameterized query for get_engine.
clickhouse_connect/cc_sqlalchemy/ddl/custom.py Uses format_str for Replicated engine args and fixes missing closing ) in emitted DDL.
tests/unit_tests/test_sqlalchemy/test_create_database.py Adds unit tests for database DDL generation and escaping.
CHANGELOG.md Documents the Replicated DDL fix and bound-parameter/escaping changes.

Comment thread clickhouse_connect/cc_sqlalchemy/inspector.py
@joe-clickhouse joe-clickhouse merged commit f0cedf7 into main May 5, 2026
41 checks passed
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