Skip to content

Add regression tests for kickoff_for_each inside flows (#4385)#4386

Open
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin/1770331246-fix-4385-kickoff-for-each-inside-flow
Open

Add regression tests for kickoff_for_each inside flows (#4385)#4386
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin/1770331246-fix-4385-kickoff-for-each-inside-flow

Conversation

@devin-ai-integration
Copy link
Contributor

Add regression tests for kickoff_for_each inside flows (#4385)

Summary

Adds 4 regression tests for issue #4385, where akickoff_for_each (and related methods) failed with a Pydantic ValidationError on the parent_flow field when a Crew was created and copied inside a Flow[TypedState] method.

The root cause was that the old FlowTrackable mixin stored a direct parent_flow: InstanceOf[Flow[Any]] reference. When crew.copy() called model_dump(), this field was serialized and re-passed to the Crew(...) constructor, where Pydantic's InstanceOf validator rejected the dynamically-created _FlowGeneric type. This was already fixed in 9d7f4537 by replacing the parent_flow field with lightweight context variables (_flow_id, _request_id).

This PR adds test coverage only — no production code changes. The four new tests are:

Test What it exercises
test_crew_copy_inside_typed_flow crew.copy() inside a Flow[MyState] method
test_kickoff_for_each_inside_flow crew.kickoff_for_each() inside a sync Flow method
test_kickoff_for_each_async_inside_flow crew.kickoff_for_each_async() inside an async Flow method
test_akickoff_for_each_inside_flow crew.akickoff_for_each() inside an async Flow method

Review & Testing Checklist for Human

  • Verify these tests would have caught the original bug: If the old parent_flow: InstanceOf[Flow[Any]] field were reintroduced on FlowTrackable, these tests should fail with the reported ValidationError. Consider temporarily reverting flow_trackable.py to confirm.
  • Assess mock depth: The kickoff/kickoff_async/akickoff methods are mocked, so these tests primarily exercise the crew.copy() path inside a flow context. They do not test full end-to-end execution. Decide if that's sufficient coverage.
  • Check CI results: Confirm all 4 new tests pass across all Python versions in CI.

Notes

Add tests covering crew.copy(), kickoff_for_each, kickoff_for_each_async,
and akickoff_for_each when called inside a Flow[MyState] method.

These tests ensure the fix from commit 9d7f453 (replacing parent_flow
field with context variables) prevents the Pydantic validation error
reported in issue #4385.

Co-Authored-By: João <joao@crewai.com>
@devin-ai-integration
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

Regression test for https://github.com/crewAIInc/crewAI/issues/4385
"""

class MyState(BaseModel):
Regression test for https://github.com/crewAIInc/crewAI/issues/4385
"""

class MyState(BaseModel):
Regression test for https://github.com/crewAIInc/crewAI/issues/4385
"""

class MyState(BaseModel):
Regression test for https://github.com/crewAIInc/crewAI/issues/4385
"""

class MyState(BaseModel):
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