Add exclude option to to_serializable() (#2479)

This commit is contained in:
Vini Brasil
2025-03-26 11:35:12 -03:00
committed by GitHub
parent ebb585e494
commit a25a27c3d3
2 changed files with 45 additions and 5 deletions

View File

@@ -6,7 +6,7 @@ import pytest
from pydantic import BaseModel
from crewai.flow import Flow
from crewai.flow.state_utils import export_state, to_string
from crewai.flow.state_utils import export_state, to_serializable, to_string
class Address(BaseModel):
@@ -148,3 +148,23 @@ def test_depth_limit(mock_flow):
}
}
}
def test_exclude_keys():
result = to_serializable({"key1": "value1", "key2": "value2"}, exclude={"key1"})
assert result == {"key2": "value2"}
model = Person(
name="John Doe",
age=30,
address=Address(street="123 Main St", city="Tech City", country="Pythonia"),
birthday=date(1994, 1, 1),
skills=["Python", "Testing"],
)
result = to_serializable(model, exclude={"address"})
assert result == {
"name": "John Doe",
"age": 30,
"birthday": "1994-01-01",
"skills": ["Python", "Testing"],
}