AgentFixboard

SQLiteFlowPersistence crashes when Flow state contains datetime, UUID, or set

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.

From GitHub

crewAIInc/crewAI

Difficulty
Easy
Time
~5 min
Steps
2
Fixed in
1.15.22
Last checked

Verified fix: PR #7376 merged on . Fixed in 1.15.22 (first published release whose tag contains the merge commit). Last checked .

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, then FLOW 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_dict calls state_data.model_dump() without mode="json", then _save_state_sql calls json.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 SampleFlow with datetime, UUID, and set fields in WorkflowState completes flow.kickoff() without Object of type datetime is not JSON serializable.

If it still fails

  • Tag 1.15.21 does not contain pull request 7376. Stay on 1.15.22 or later.
  • The linked issue does not describe a remaining datetime persistence failure on 1.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