Commit b2bfcbe
Override DATETIME/DATE colspecs for native datetime passthrough
The dqlite DBAPI now returns datetime.datetime directly for columns the
server tags as ISO8601 or UNIXTIME (matching psycopg/mysqlclient/PEP 249).
SQLAlchemy's inherited sqlite.DATETIME and sqlite.DATE types, by contrast,
assume pysqlite-style string returns and call fromisoformat on the value —
which crashes when handed a datetime.
Registers two dialect-local types via colspecs:
- _DqliteDateTime: bind_processor and result_processor both return None,
so datetime objects flow through unchanged in both directions (the
DBAPI stringifies on bind and datetime-ifies on result).
- _DqliteDate: bind is passthrough; result narrows datetime.datetime to
datetime.date on read, since the server tags DATE columns as ISO8601
(see dqlite-upstream/src/query.c) and the DBAPI doesn't know to
downcast.
TIME is deliberately not overridden: the server does not tag TIME columns
specially (they're plain TEXT), so SQLAlchemy's string-based Time
processor continues to work as-is.
Async dialect (aio.DqliteDialect_aio) inherits colspecs from the sync
dialect, so it picks up the overrides automatically.
Tests tightened and extended in test_orm_operations.py: the existing
test_datetime_types now asserts tzinfo-is-None and full value equality
(not just field-by-field). New tests cover Column(Date) returning
datetime.date exactly (not a datetime subclass) and NULL DateTime
round-trip.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 0bb7913 commit b2bfcbe
2 files changed
Lines changed: 86 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
10 | 45 | | |
11 | 46 | | |
12 | 47 | | |
| |||
22 | 57 | | |
23 | 58 | | |
24 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
25 | 68 | | |
26 | 69 | | |
27 | 70 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
66 | 74 | | |
67 | 75 | | |
68 | 76 | | |
| |||
192 | 200 | | |
193 | 201 | | |
194 | 202 | | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
201 | 238 | | |
202 | 239 | | |
203 | 240 | | |
| |||
0 commit comments