Skip to content

Remove last pydantic.v1 vestiage#6321

Merged
masenf merged 1 commit intomainfrom
masenf/pydantic-v1-missed
Apr 10, 2026
Merged

Remove last pydantic.v1 vestiage#6321
masenf merged 1 commit intomainfrom
masenf/pydantic-v1-missed

Conversation

@masenf
Copy link
Copy Markdown
Collaborator

@masenf masenf commented Apr 10, 2026

No description provided.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 10, 2026

Greptile Summary

This PR removes the last pydantic.v1 compatibility code from _transform_event_arg, specifically the import of pydantic.v1.BaseModel and the corresponding parse_obj deserialization branch. After this change, only pydantic v2 models (using model_validate) are auto-deserialized from dicts in event handler payloads.

  • This is a breaking change for any user who type-hints event handler arguments with pydantic.v1.BaseModel subclasses — those arguments will now receive a raw dict from the frontend instead of a deserialized model instance, likely causing AttributeError at runtime. It may be worth calling this out in a changelog or migration guide.

Confidence Score: 4/5

Safe to merge if pydantic.v1 model event args are not used in the wild, but this is a silent runtime breakage for anyone who is.

The change is intentional and minimal, but silently breaks any event handler that type-hints a pydantic.v1.BaseModel argument — those handlers will receive a raw dict and likely raise AttributeError at runtime. Whether any active users are affected is unknown, so a changelog entry or deprecation notice would be prudent before merging.

packages/reflex-base/src/reflex_base/event/processor/base_state_processor.py — the _transform_event_arg function is the sole changed site.

Important Files Changed

Filename Overview
packages/reflex-base/src/reflex_base/event/processor/base_state_processor.py Removes pydantic.v1.BaseModel import and parse_obj deserialization branch; pydantic v1 compat models will no longer be auto-deserialized in event handler payloads — a silent breaking change for users of pydantic.v1.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["_transform_event_arg(value, hinted_args)"] --> B{value is dict\nand hinted_args is type?}
    B -- No --> G[Other branches: list, Enum, deserializer]
    B -- Yes --> C{issubclass\nModel / reflex?}
    C -- Yes --> D["hinted_args(**filtered_fields)"]
    C -- No --> E{is dataclass?}
    E -- Yes --> F["hinted_args(**value)"]
    E -- No --> H{pydantic installed?}
    H -- No --> G
    H -- Yes --> I{issubclass\nBaseModelV2?}
    I -- Yes --> J["model_validate(value)"]
    I -- No --> K["⚠️ raw dict returned\n(pydantic.v1 models land here)"]

    style K fill:#ffcccc,stroke:#cc0000
Loading

Reviews (1): Last reviewed commit: "Remove last pydantic.v1 vestiage" | Re-trigger Greptile

Comment on lines 116 to 120
if find_spec("pydantic"):
from pydantic import BaseModel as BaseModelV2
from pydantic.v1 import BaseModel as BaseModelV1

if issubclass(hinted_args, BaseModelV1):
return hinted_args.parse_obj(value)
if issubclass(hinted_args, BaseModelV2):
return hinted_args.model_validate(value)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Silent breaking change for pydantic.v1 model arguments

Any event handler that type-hints an argument as a pydantic.v1.BaseModel subclass will now receive a raw dict from the frontend instead of a deserialized model instance. Because pydantic.v1.BaseModel and pydantic.BaseModel (v2) are completely separate class hierarchies, issubclass(hinted_args, BaseModelV2) returns False for v1 compat models — the dict falls through all branches and is passed as-is. Handlers that then access attributes (e.g. model.name) will raise AttributeError at runtime with no helpful error message.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 10, 2026

Merging this PR will not alter performance

✅ 9 untouched benchmarks


Comparing masenf/pydantic-v1-missed (3ad268e) with main (ecccd05)

Open in CodSpeed

@masenf masenf merged commit 96c4487 into main Apr 10, 2026
40 checks passed
@masenf masenf deleted the masenf/pydantic-v1-missed branch April 10, 2026 23: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.

2 participants