Skip to content

Conversation

devin-ai-integration[bot]
Copy link
Contributor

Fix task.copy() to preserve NOT_SPECIFIED context (fixes #3691)

Summary

This PR fixes a bug where Task.copy() incorrectly converted NOT_SPECIFIED context values to None during task copying. This affected kickoff_for_each and kickoff_for_each_async methods when copying tasks with the default NOT_SPECIFIED context.

Root Cause: The original logic only checked if isinstance(self.context, list), causing NOT_SPECIFIED (which is falsy) to fall through to the else None case.

Fix: Added an explicit check for NOT_SPECIFIED before the list/None handling to preserve the sentinel value.

Changes:

  • Added if self.context is NOT_SPECIFIED: check in Task.copy() method
  • Renamed import copyshallow_copy for clarity
  • Added 3 comprehensive tests covering NOT_SPECIFIED, list context, and None context cases

Review & Testing Checklist for Human

  • Verify new tests pass and actually reproduce the original bug - Run pytest tests/test_task.py::test_task_copy_preserves_not_specified_context -vv to confirm the test fails without the fix
  • Test kickoff_for_each workflows end-to-end - Create a crew with tasks using default context and verify kickoff_for_each([input1, input2]) works correctly without converting NOT_SPECIFIED to None
  • Check for regressions in task copying - Run existing task tests to ensure list context and None context still work as expected

Notes

Link to Devin run: https://app.devin.ai/sessions/136dd806c654415fa702281360a2e462
Requested by: João ([email protected])

Environment Note: Local testing was blocked by corrupted uv.lock file, so CI verification is essential. The fix logic matches the pattern from PR #3690 which had the same solution.

- Add check in task.copy() to preserve NOT_SPECIFIED context value
- Previously, NOT_SPECIFIED was being converted to None during copy
- This affected kickoff_for_each and kickoff_for_each_async methods
- Add comprehensive tests covering NOT_SPECIFIED, list, and None contexts
- Rename import 'copy' to 'shallow_copy' for clarity

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

- Add explicit type hint for cloned_context to fix mypy error
- Fix pre-existing lint error: use raw string for regex pattern

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.

[BUG] Kickoff_for_each and Kickoff_for_each_async doesn't copy task correctly.

0 participants