Skip to content

Support TzDate, TzDatetime and TzTimestamp types#857

Open
vgvoleg wants to merge 5 commits into
mainfrom
feature/405-tz-types
Open

Support TzDate, TzDatetime and TzTimestamp types#857
vgvoleg wants to merge 5 commits into
mainfrom
feature/405-tz-types

Conversation

@vgvoleg

@vgvoleg vgvoleg commented Jul 3, 2026

Copy link
Copy Markdown
Member

Fixes #405.

TzDate, TzDatetime and TzTimestamp were not registered in PrimitiveType, so reading them crashed with AttributeError: 'NoneType' object has no attribute 'get_value'. This registers all three (stored on the wire as "<value>,<zone>" text):

  • Read (native result sets): a tz-aware datetime carrying a zoneinfo.ZoneInfo (TzDate at midnight); the raw "<value>,<zone>" string when the matching with_native_*_in_result_sets option is off, mirroring the other date/time types.
  • Write: a tz-aware datetime (its local wall-clock + ZoneInfo name is stored) or the raw string.

Based on drop-python-3.9-and-proto3 for the Python 3.10 baseline (stdlib zoneinfo); retarget to main once that merges.

@codecov-commenter

codecov-commenter commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.30%. Comparing base (a4949f4) to head (89aa279).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #857      +/-   ##
==========================================
+ Coverage   81.23%   81.30%   +0.06%     
==========================================
  Files          94       94              
  Lines       12121    12165      +44     
  Branches     1186     1194       +8     
==========================================
+ Hits         9847     9891      +44     
  Misses       1809     1809              
  Partials      465      465              
Flag Coverage Δ
integration 79.09% <100.00%> (+0.07%) ⬆️
unit 47.27% <27.27%> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
ydb/types.py 95.34% <100.00%> (+0.73%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@robot-vibe-db

robot-vibe-db Bot commented Jul 3, 2026

Copy link
Copy Markdown

Full analysis log

Analysis performed by claude, claude-opus-4-6.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds full SDK support for YDB’s timezone-carrying primitive types (TzDate, TzDatetime, TzTimestamp) by registering them in PrimitiveType and providing Python ↔ wire conversions, plus tests and documentation updates to prevent the AttributeError crash reported in #405.

Changes:

  • Register TzDate / TzDatetime / TzTimestamp in ydb.types.PrimitiveType and implement text-based (de)serialization using zoneinfo.
  • Add unit tests for both query and async table clients covering raw-string and native-datetime modes.
  • Document the new types and add a user-facing changelog entry.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
ydb/types.py Adds tz parsing/formatting helpers and registers tz primitive types in PrimitiveType.
tests/query/test_types.py Extends query type round-trip tests for tz types (string + native datetime).
tests/aio/test_types.py Extends async table client tests for tz types.
docs/types.rst Documents tz types mapping and result-set behavior.
CHANGELOG.md Adds a user-facing entry for tz type support.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ydb/types.py Outdated
Comment thread docs/types.rst Outdated
@vgvoleg vgvoleg force-pushed the drop-python-3.9-and-proto3 branch from 3f14e94 to 2f5b90f Compare July 6, 2026 07:28
Base automatically changed from drop-python-3.9-and-proto3 to main July 6, 2026 07:36
vgvoleg added 3 commits July 6, 2026 10:38
Register the timezone-carrying primitive types so query results and
parameters map to/from tz-aware datetime via zoneinfo (raw string when
native result-set conversion is disabled). Reading them previously
crashed with AttributeError.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 9 comments.

Comment thread tests/query/test_types.py Outdated
Comment thread tests/query/test_types.py Outdated
Comment thread tests/query/test_types.py Outdated
Comment thread tests/query/test_types.py Outdated
Comment thread tests/query/test_types.py Outdated
Comment thread tests/query/test_types.py Outdated
Comment thread tests/query/test_types.py Outdated
Comment thread tests/aio/test_types.py Outdated
Comment thread tests/aio/test_types.py Outdated

@robot-vibe-db robot-vibe-db Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Review Summary

Verdict: ✅ No critical issues found

Critical issues

No critical issues found.

Other findings

  • Minor | Medium: _parse_tz exception handling — ZoneInfo() can raise exceptions beyond ZoneInfoNotFoundError for certain malformed keys (e.g. empty string raises ValueError on CPython). While unlikely with valid YDB wire data, this bypasses the graceful fallback. — ydb/types.py:95
  • Minor | Low: TZ types reuse the existing non-TZ native-mode settings (_native_date_in_result_sets, etc.) rather than having dedicated toggles. Users cannot independently control native conversion for e.g. Date vs TzDate. — ydb/types.py:107
  • Nit | Low: _to_tz_timestamp always writes 6-digit microseconds via strftime("%f"), producing .000000 when microseconds are zero. If YDB normalizes the wire representation (stripping trailing zeros), a write→read→write cycle could produce different strings for the same value. — ydb/types.py:140
  • Nit | Low: No test covers TzDate with non-midnight time components (lossy truncation) or TzTimestamp with zero microseconds (format difference). These edge cases would help document expected behavior. — tests/query/test_types.py

This review was generated automatically. Critical issues require attention; other findings are advisory.
If this comment was useful, please give it a 👍 — it helps us improve the review bot.

Comment thread ydb/types.py Outdated
Comment thread ydb/types.py
Comment thread ydb/types.py Outdated
@robot-vibe-db

robot-vibe-db Bot commented Jul 6, 2026

Copy link
Copy Markdown

Full analysis log

Analysis performed by claude, claude-opus-4-6.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature: Support time with timezone types

3 participants