Skip to content

Fix TypeError when reading timestamps via the driver's time_zone option#287

Merged
florinutz merged 1 commit into
mainfrom
fix/datetime-idempotency
Jul 3, 2026
Merged

Fix TypeError when reading timestamps via the driver's time_zone option#287
florinutz merged 1 commit into
mainfrom
fix/datetime-idempotency

Conversation

@florinutz

@florinutz florinutz commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

The CrateDB driver (crate-python) can return timezone-aware datetime objects when its time_zone argument is configured. But using that option through the SQLAlchemy dialect crashed:

TypeError: strptime() argument 1 must be str, not datetime.datetime

Root cause

Reading a TIMESTAMP involves two layers. Normally the driver passes the raw epoch-millis value through and the dialect's DateTime.result_processor converts it to a datetime. When time_zone is set, the driver converts the value to a datetime first — so the dialect's processor received an already-converted datetime, tried to convert it (TypeError, caught), then fell through to strptime(value, ...) (TypeError, uncaught) → crash.

The processor assumed it was always first in line to do the conversion.

Fix

Make DateTime.result_processor idempotent: if the value is already a datetime (the driver converted it), pass it through unchanged.

if isinstance(value, datetime):
    return value

Closes #92 (was actually already done)

@florinutz
florinutz requested review from bgunebakan and kneth July 2, 2026 09:49
@florinutz florinutz added bug Something isn't working python Pull requests that update Python code labels Jul 2, 2026
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d050c811-f77b-466c-a92d-83f8b02be2b5

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/datetime-idempotency

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@florinutz florinutz self-assigned this Jul 2, 2026
@florinutz florinutz changed the title Fix TypeError when reading timestamps via the driver's time_zone option Fix TypeError when reading timestamps via the driver's time_zone option Jul 2, 2026

@bgunebakan bgunebakan 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.

Thank you!

@florinutz
florinutz merged commit aca656d into main Jul 3, 2026
27 checks passed
@florinutz
florinutz deleted the fix/datetime-idempotency branch July 3, 2026 15:26
@amotl

amotl commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Reading a TIMESTAMP involves two layers. [...] Make DateTime.result_processor idempotent.

Excellent, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for timezone aware datetime objects to SQLAlchemy dialect

4 participants