Symptom
A Flow with @persist or SQLiteFlowPersistence raises RuntimeError: State persistence failed: Object of type datetime is not JSON serializable when the Pydantic state includes datetime, UUID, or set.
Evidence what you'll see
- The report's failure line is
Failed to persist state for method step_one: Object of type datetime is not JSON serializable, thenFLOW CRASHED: RuntimeError: State persistence failed: Object of type datetime is not JSON serializable. - The crash is in
lib/crewai/src/crewai/flow/persistence/sqlite.py:_to_state_dictcallsstate_data.model_dump()withoutmode="json", then_save_state_sqlcallsjson.dumps(state_dict).
Why it happens
Pydantic v2 model_dump() keeps native Python types. json.dumps then raises TypeError: Object of type datetime is not JSON serializable. Pull request 7376 uses model_dump(mode="json") for BaseModel state, serializes dict state through to_serializable, and adds default=str on those json.dumps calls.
Affected versions
crewAI 1.15.20, crewAI Tools 1.15.20, Python 3.12, macOS Sonoma, venv. The repro uses SQLiteFlowPersistence("test_flow.db").
Fix steps
0 of 2 done
Your check marks stay in this browser only.
How to check it worked
- The report's
SampleFlowwithdatetime,UUID, andsetfields inWorkflowStatecompletesflow.kickoff()withoutObject of type datetime is not JSON serializable.
If it still fails
- Tag
1.15.21does not contain pull request 7376. Stay on1.15.22or later. - The linked issue does not describe a remaining
datetimepersistence failure on1.15.22.
Sources and credit
Summarized in our own words from these public reports. Credit goes to their authors.
Provided as is, without warranty. Try changes in a non-production environment and back up first. Security-related steps: verify against the official docs. Terms · Request removal or attribution change
Hit an error we don't cover? Submit it