Summary
Following the pattern established by D1Boolean, D1LargeBinary, D1DateTime, and D1Date, we need custom type processors for additional SQLAlchemy types that would cause D1_TYPE_ERROR when used with Cloudflare D1.
D1 only accepts primitive bind parameters (string, number, null, ArrayBuffer). Python objects passed directly will raise:
D1_TYPE_ERROR: Type 'object' not supported for value '...'
Types needing processors
Time — HIGH priority
- Python
datetime.time objects pass through unchanged → D1_TYPE_ERROR
- Fix:
D1Time processor converting to/from ISO 8601 strings (HH:MM:SS)
- Same pattern as
D1Date and D1DateTime
UUID — MEDIUM priority
- Python
uuid.UUID objects may pass through unchanged → D1_TYPE_ERROR
- Fix:
D1UUID processor converting to/from string (.hex or hyphenated format)
Enum — MEDIUM priority
- Python
enum.Enum objects may not get converted to strings → D1_TYPE_ERROR
- Fix:
D1Enum processor extracting the enum value as a string
Interval — MEDIUM priority
- Python
timedelta objects get converted to datetime internally but still arrive as objects → D1_TYPE_ERROR
- Fix:
D1Interval processor converting to/from a numeric or string representation
- Less commonly used than the others
Types that are already safe (no action needed)
Numeric / Float — converted to primitive float by default
JSON — json.dumps() produces a string
PickleType — pickles to bytes, handled by D1LargeBinary
References
Summary
Following the pattern established by
D1Boolean,D1LargeBinary,D1DateTime, andD1Date, we need custom type processors for additional SQLAlchemy types that would causeD1_TYPE_ERRORwhen used with Cloudflare D1.D1 only accepts primitive bind parameters (string, number, null, ArrayBuffer). Python objects passed directly will raise:
Types needing processors
Time— HIGH prioritydatetime.timeobjects pass through unchanged → D1_TYPE_ERRORD1Timeprocessor converting to/from ISO 8601 strings (HH:MM:SS)D1DateandD1DateTimeUUID— MEDIUM priorityuuid.UUIDobjects may pass through unchanged → D1_TYPE_ERRORD1UUIDprocessor converting to/from string (.hexor hyphenated format)Enum— MEDIUM priorityenum.Enumobjects may not get converted to strings → D1_TYPE_ERRORD1Enumprocessor extracting the enum value as a stringInterval— MEDIUM prioritytimedeltaobjects get converted todatetimeinternally but still arrive as objects → D1_TYPE_ERRORD1Intervalprocessor converting to/from a numeric or string representationTypes that are already safe (no action needed)
Numeric/Float— converted to primitive float by defaultJSON—json.dumps()produces a stringPickleType— pickles to bytes, handled byD1LargeBinaryReferences
D1Boolean,D1Date,D1DateTime,D1LargeBinaryindialect.pyD1Date)