mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-25 16:18:13 +00:00
Fix Union type handling in Pydantic output generation
- Fixed generate_model_description to correctly handle Union types - Union types without None are now properly formatted as Union[type1, type2] - Union types with None are correctly wrapped in Optional[Union[...]] - Added support for Python 3.10+ pipe syntax (int | str | None) - Added comprehensive tests for Union type support - Updated existing test expectations to match corrected behavior This fixes issue #3735 where Union types were incorrectly wrapped in Optional even when None was not part of the Union. Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
@@ -596,5 +596,5 @@ def test_generate_model_description_union_field():
|
||||
field: int | str | None
|
||||
|
||||
description = generate_model_description(UnionModel)
|
||||
expected_description = '{\n "field": int | str | None\n}'
|
||||
expected_description = '{\n "field": Optional[Union[int, str]]\n}'
|
||||
assert description == expected_description
|
||||
|
||||
Reference in New Issue
Block a user