Skip to content

add PEP 249 DB API constructors - #940

Merged
joe-clickhouse merged 3 commits into
mainfrom
joe/919-dbapi-constructors
Aug 6, 2026
Merged

add PEP 249 DB API constructors#940
joe-clickhouse merged 3 commits into
mainfrom
joe/919-dbapi-constructors

Conversation

@joe-clickhouse

Copy link
Copy Markdown
Contributor

Summary

  • Adds the PEP 249 Binary, Date, Time, Timestamp, and *FromTicks constructors.
  • Fixes SQLAlchemy LargeBinary inserts raising AttributeError when the dialect calls dbapi.Binary.
  • Adds direct constructor, local-time tick conversion, fractional tick, and SQLAlchemy consumer coverage.
  • Leaves time binding and the pre-existing LargeBinary read behavior for separate work.
  • Addresses the Binary constructor failure in Two Core types cannot be bound through the DBAPI: LargeBinary (no PEP 249 Binary constructor) and Time #919 but does not fully close it.

Co-authored by @sankalpsthakur

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 completes the PEP 249 constructor surface for clickhouse_connect.dbapi by adding Binary, Date, Time, Timestamp, plus the *FromTicks helpers. This resolves SQLAlchemy LargeBinary binding failures where the dialect expects dbapi.Binary to exist.

Changes:

  • Add PEP 249 type constructors and *FromTicks functions to clickhouse_connect.dbapi.
  • Add unit tests covering constructors and verifying SQLAlchemy’s import_dbapi() exposes Binary.
  • Update documentation and changelog to reflect the DB-API surface addition.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
clickhouse_connect/dbapi/__init__.py Adds PEP 249 constructors (Binary, Date, Time, Timestamp) and tick-based constructor functions.
tests/unit_tests/test_driver/test_dbapi_types.py New unit tests validating constructor behavior and SQLAlchemy dialect consumption.
docs/driver-api.mdx Documents the newly supported PEP 249 constructors and tick helpers.
CHANGELOG.md Adds a user-visible bugfix entry referencing the SQLAlchemy LargeBinary binding fix and issue #919.

@joe-clickhouse
joe-clickhouse merged commit 32c93d8 into main Aug 6, 2026
37 checks passed
@joe-clickhouse
joe-clickhouse deleted the joe/919-dbapi-constructors branch August 6, 2026 00:59
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