Skip to content

Conversation

devin-ai-integration[bot]
Copy link
Contributor

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 a kwargs 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:

  • Updated _create_initial_state() method signature to accept optional kwargs
  • Modified all 4 state instantiation paths to use **(kwargs or {})
  • Removed redundant _initialize_state(kwargs) call from Flow.__init__()
  • Added 5 comprehensive tests covering required fields, optional fields, mixed scenarios, and backward compatibility

Review & Testing Checklist for Human

  • Verify backward compatibility: Test existing Flows with FlowState subclasses still work without providing kwargs
  • Test the original issue: Create a Flow with a Pydantic state having required fields and confirm it works with provided kwargs
  • Check edge cases: Test mixed required/optional fields, default value overrides, and that id auto-generation still works properly
  • Run full test suite: Ensure no regressions in existing Flow functionality across the codebase

Recommended Test Plan

  1. Create a simple Flow with required Pydantic fields (name: str, age: int) and verify it works: MyFlow(name="test", age=25)
  2. Test an existing Flow that uses FlowState subclasses to ensure no regression
  3. Test a Flow with mixed required/optional fields to verify defaults work correctly

Notes

- Modified _create_initial_state() to accept kwargs parameter
- Updated all model instantiation points to use kwargs
- Removed redundant _initialize_state() call from __init__()
- Added comprehensive tests for required fields, optional fields, and backward compatibility
- Fixes issue #3629

Co-Authored-By: João <[email protected]>
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Copy link

cursor bot commented Oct 1, 2025

You have run out of free Bugbot PR reviews for this billing cycle. This will reset on October 28.

To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

devin-ai-integration bot and others added 2 commits October 1, 2025 17:30
- Add ValidationError import from pydantic
- Use ValidationError instead of generic Exception in test
- Remove unused flow variable
- Apply ruff formatting (import ordering and getattr simplification)

Co-Authored-By: João <[email protected]>
- Import PrinterColor type from utilities.printer
- Replace unused variable 'condition_type' with '_' at line 1091
- Fix type annotation for '_log_flow_event' color parameter to use PrinterColor instead of str

These were pre-existing errors that prevented CI from passing after modifying flow.py

Co-Authored-By: João <[email protected]>
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.

0 participants