Fix Flow initialization with Pydantic models having required fields #3630
+127
−17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix Flow initialization with Pydantic models having required fields
Summary
Fixes issue #3629 where Flow initialization would fail with a
ValidationError
when using Pydantic state models that have required (non-optional) fields.Root Cause: The
_create_initial_state()
method was instantiating state models without any arguments (state_type()
), causing Pydantic validation to fail for required fields.Solution: Modified
_create_initial_state()
to accept akwargs
parameter and pass it to all state model instantiation points. Also removed the redundant_initialize_state(kwargs)
call from__init__()
since kwargs are now handled during initial state creation.Key Changes:
_create_initial_state()
method signature to accept optionalkwargs
**(kwargs or {})
_initialize_state(kwargs)
call fromFlow.__init__()
Review & Testing Checklist for Human
Recommended Test Plan
MyFlow(name="test", age=25)
Notes
test_flow.py
pass, plus 5 new tests added