Fix SQLAlchemy Decimal arithmetic type adaptation - #1028
Merged
Conversation
joe-clickhouse
requested
a lite review from Copilot
and removed request for
peter-leonov-ch
September 6, 2026 14:35
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The change is narrowly scoped to SQLAlchemy type adaptation and is backed by targeted unit and integration regression tests covering the reported failure mode.
Pull request overview
Fixes SQLAlchemy expression type adaptation for cc_sqlalchemy Decimal so arithmetic like col * 100 no longer triggers a Decimal() construction with invalid default precision/scale, while keeping configured ClickHouse decimal types and SQLAlchemy numeric promotion behavior intact.
Changes:
- Override
Decimal._expression_adaptationsto reuse SQLAlchemyNumericadaptation rules (avoids constructing unconfiguredDecimal()during expression adaptation). - Add unit coverage for literal, composed, mixed-type, Interval, and TypeDecorator arithmetic scenarios, plus constructor validation.
- Add integration coverage that compiles and executes representative decimal arithmetic and validates round-trip
decimal.Decimalresults.
File summaries
| File | Description |
|---|---|
| clickhouse_connect/cc_sqlalchemy/datatypes/sqltypes.py | Reuses SQLAlchemy Numeric expression adaptation rules for ClickHouse Decimal types to prevent invalid default construction during arithmetic. |
| tests/unit_tests/test_sqlalchemy/test_decimal_arithmetic.py | Adds unit tests ensuring decimal arithmetic builds correctly and preserves configured types, promotion rules, and TypeDecorator processing. |
| tests/integration_tests/test_sqlalchemy/test_decimal_arithmetic.py | Adds integration tests validating compiled SQL + parameter binding and actual ClickHouse round-trip results for common decimal arithmetic. |
| CHANGELOG.md | Documents the user-visible bug fix and links the closed issue. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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
Decimal arithmetic such as
col * 100now builds correctly. Reuses SQLAlchemy's Numeric adaptation rules while preserving configured types and constructor validation.Closes #1027
Checklist
Delete items not relevant to your PR: