Skip to content

Conversation

@adhami3310
Copy link
Member

fixes #5811

@codspeed-hq
Copy link

codspeed-hq bot commented Sep 25, 2025

CodSpeed Performance Report

Merging #5822 will not alter performance

Comparing add-deser-for-date-and-time (79175c5) with main (a21414d)

Summary

✅ 8 untouched

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Overview

Summary

This PR adds deserialization support for datetime.datetime, datetime.date, and datetime.time types in event handler payloads, resolving issue #5811 where datetime parameters were received as strings instead of proper datetime objects in decentralized event handlers.

Key Changes:

  • Added _deserializers dictionary mapping datetime types to their fromisoformat methods
  • Extended the existing string-to-type conversion logic to handle datetime types alongside int/float
  • Leverages Python's built-in fromisoformat methods for robust ISO format parsing

Issues Found:

  • Docstring needs updating to reflect new datetime type support
  • Warning message is misleading for datetime conversions (suggests they're unexpected when they're now intended behavior)

Confidence Score: 4/5

  • This PR is generally safe to merge with minor documentation and messaging improvements needed
  • The core implementation is sound and addresses the reported issue effectively using Python's built-in ISO format parsing. The changes are minimal and focused. Two minor issues exist: an outdated docstring and a misleading warning message, but these don't affect functionality.
  • No files require special attention - the issues identified are minor documentation/messaging updates

Important Files Changed

File Analysis

Filename        Score        Overview
reflex/state.py 4/5 Adds datetime deserialization support to event handlers; includes outdated docstring and misleading warning message

Sequence Diagram

sequenceDiagram
    participant Client as Frontend Client
    participant EventHandler as Event Handler
    participant BaseState as BaseState._process_event
    participant Deserializer as _deserializers
    participant Datetime as datetime.fromisoformat

    Client->>EventHandler: Call decentralized event handler
    Note over Client,EventHandler: payload contains datetime as ISO string<br/>"2023-12-25T10:30:00"
    
    EventHandler->>BaseState: Process event with payload
    BaseState->>BaseState: Get type hints for handler parameters
    BaseState->>BaseState: Check if parameter type is datetime/date/time
    
    alt String value with datetime type hint
        BaseState->>Deserializer: Look up deserializer for datetime type
        Deserializer-->>BaseState: Return datetime.fromisoformat function
        BaseState->>Datetime: Call fromisoformat("2023-12-25T10:30:00")
        Datetime-->>BaseState: Return datetime object
        BaseState->>BaseState: Update payload with datetime object
    else String value with int/float type hint
        BaseState->>BaseState: Convert using int() or float()
    else Other types
        BaseState->>BaseState: No conversion applied
    end
    
    BaseState->>EventHandler: Call handler with converted payload
    EventHandler-->>Client: Return response
Loading

1 file reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Copy link
Collaborator

@masenf masenf left a comment

Choose a reason for hiding this comment

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

neat!

@adhami3310 adhami3310 merged commit 4bc4cb8 into main Sep 25, 2025
52 of 53 checks passed
@adhami3310 adhami3310 deleted the add-deser-for-date-and-time branch September 25, 2025 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decentralized event handler with datetime parameter receives a string

3 participants