Skip to content

Add type processors for Time, Interval, UUID, and Enum #18

Description

@CollierKing

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
  • JSONjson.dumps() produces a string
  • PickleType — pickles to bytes, handled by D1LargeBinary

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions