fix: protect SQLAlchemy reflection from String bytes format - #923
Closed
sankalpsthakur wants to merge 1 commit into
Closed
fix: protect SQLAlchemy reflection from String bytes format#923sankalpsthakur wants to merge 1 commit into
sankalpsthakur wants to merge 1 commit into
Conversation
set_default_formats("String", "bytes") previously broke reflection:
get_columns raised TypeError on bytes type names, and get_table_names
returned bytes table names. Thread query_formats through the DB-API
cursor and dialect (mirroring the existing settings path), and apply
the core driver's _INTERNAL_QUERY_FORMATS to metadata queries so schema
introspection always decodes String as str.
Fixes ClickHouse#920
AI disclosure: This change was drafted with AI assistance and reviewed
by the author before submission.
sankalpsthakur
requested review from
joe-clickhouse and
peter-leonov-ch
as code owners
August 1, 2026 08:30
3 tasks
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #920.
set_default_formats("String", "bytes")(orset_read_format("String", "bytes")) is a global read format that makesStringcolumns decode asbytes. The core driver already protects orchestration queries via_INTERNAL_QUERY_FORMATS = {"String": "string"}, but the SQLAlchemy reflection path (cc_sqlalchemyinspector + dialect metadata methods) issued ordinary DB-API queries and was unprotected.Under the global bytes format this caused:
Inspector.get_columns()/Table(..., autoload_with=...)raisedTypeError: a bytes-like object is required, not 'str'onrow.type.replace("\n", "").get_table_names()returned[b'my_table']instead of['my_table'], and engine/comment comparisons likerow.engine == "Dictionary"failed.Changes
query_formatsthroughdbapi.Cursor.execute/executemanyand the SQLAlchemy dialectdo_execute*methods, mirroring the existingsettings/execution_optionsplumbing._INTERNAL_QUERY_FORMATSoverride to all SQLAlchemy metadata queries (DESCRIBE TABLE,system.tables,SHOW TABLES/SHOW DATABASES, dictionary create SQL, etc.) viawith_internal_query_formats(...).Checklist
AI disclosure
This change was drafted with AI assistance and reviewed by the author before submission.
AI/LLM disclosure