Skip to content

Conversation

devin-ai-integration[bot]
Copy link
Contributor

Fix task configuration with None context parameter in YAML

Summary

Fixes #3696 - Tasks can now be configured with context: None in YAML without causing a KeyError.

Root Cause: When context: None is specified in YAML configuration files, yaml.safe_load() converts it to the string 'None' instead of Python's None object. The existing code attempted to iterate over this string character by character ('N', 'o', 'n', 'e'), causing a KeyError: 'N' when trying to look up task names.

The Fix: Added an isinstance(context_list, list) check in crew_base.py:_map_task_variables() before iterating the context list. This ensures only actual list values are processed, while None and other non-list values are silently ignored (the task's context remains unset).

Changes:

  • Modified src/crewai/project/crew_base.py to add type check before iterating context
  • Added test case test_task_with_none_context_from_yaml with test configurations in tests/config_none_context/
  • Test verifies both context: None case and valid context list case work correctly

Review & Testing Checklist for Human

⚠️ Important: I was unable to test this locally due to a corrupted uv.lock file in the development environment. Please verify:

  • Run the new test locally - Verify test_task_with_none_context_from_yaml passes and actually reproduces the original issue when the fix is reverted
  • Test with real crew configuration - Create a simple crew with a task that has context: None in YAML and verify it works end-to-end
  • Regression testing - Verify existing crews with valid context lists (e.g., context: [task1, task2]) still work correctly
  • Edge case testing - Consider testing other non-list context values (e.g., context: null, context: "", context: 123) to ensure they don't cause crashes

Suggested Test Plan

  1. Clone the PR branch locally
  2. Run uv run pytest tests/test_project.py::test_task_with_none_context_from_yaml -vv
  3. Create a minimal crew with YAML config containing context: None and run it
  4. Run the full test suite to check for regressions: uv run pytest tests -vv

Notes

Fixes #3696

When context: None is specified in YAML, yaml.safe_load() converts it to
the string 'None' instead of Python's None object. The code was attempting
to iterate over this string character by character, causing KeyError: 'N'
when trying to look up task names.

Changes:
- Added isinstance(context_list, list) check in crew_base.py before
  iterating context_list to handle YAML's conversion of None to string
- Added test case test_task_with_none_context_from_yaml to verify tasks
  can be configured with context: None without errors
- Added test YAML configurations in tests/config_none_context/ to
  reproduce and verify the fix

The fix ensures that only actual list values are processed, allowing
None and other non-list values to pass through without causing errors.

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

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] Task can't be configured when passing None as a context parameter via YAML

0 participants