Skip to content

fix: handle JSON string config in Mem0Storage#4537

Open
hztBUAA wants to merge 1 commit intocrewAIInc:mainfrom
hztBUAA:fix/mem0-json-string-config
Open

fix: handle JSON string config in Mem0Storage#4537
hztBUAA wants to merge 1 commit intocrewAIInc:mainfrom
hztBUAA:fix/mem0-json-string-config

Conversation

@hztBUAA
Copy link

@hztBUAA hztBUAA commented Feb 20, 2026

Summary

  • Fix Mem0Storage crashing with AttributeError when config is passed as a JSON string instead of a dict
  • Add _parse_config() static method that auto-parses JSON strings, passes dicts through, and raises clear errors for invalid inputs
  • Restore mem0_storage.py and its Storage interface (removed in New Unified Memory System #4420) so the mem0 optional integration remains available

Fixes #4423

Changes

  • lib/crewai/src/crewai/memory/storage/mem0_storage.py: Add _parse_config() method; use it in __init__ instead of bare config or {}
  • lib/crewai/src/crewai/memory/storage/interface.py: Restore the Storage abstract base class required by Mem0Storage
  • lib/crewai/tests/storage/test_mem0_storage_config.py: 11 unit tests covering JSON string parsing, dict passthrough, None default, and error cases

Test plan

  • JSON string config is auto-parsed into a dict
  • Dict config passes through unchanged (backwards compatible)
  • None defaults to empty dict
  • Invalid JSON string raises ValueError with helpful message
  • Non-dict JSON (e.g. arrays) raises TypeError
  • Non-string/dict types raise TypeError
  • All 11 new tests pass locally

🤖 Generated with Claude Code

When Mem0Storage receives config as a JSON string (common when loading
from environment variables or config files), it now automatically parses
it via json.loads() instead of crashing with AttributeError on .get().

Add _parse_config() static method that handles:
- None -> empty dict
- dict -> pass through unchanged
- JSON string -> parse with json.loads()
- invalid types -> raise clear TypeError
- invalid JSON -> raise clear ValueError

Fixes crewAIInc#4423
@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@hztBUAA
Copy link
Author

hztBUAA commented Feb 25, 2026

Thanks for the review and feedback. I am following up on this PR now and will either push the requested changes or reply point-by-point shortly.

@hztBUAA
Copy link
Author

hztBUAA commented Feb 25, 2026

Quick follow-up: I am reviewing the feedback and will update this PR shortly.

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] Mem0Storage crashes when config is provided as a JSON string

1 participant