Skip to content

Conversation

@hucruz
Copy link

@hucruz hucruz commented Jul 28, 2025

What does this PR do?

This PR fixes an issue with the JSON serialization of Session objects in the RedisMemorySessionService. Specifically, it adds a robust serializer that correctly handles non-JSON-native types such as:

  • set → converted to list
  • bytes → decoded to utf-8 or fallback to repr
  • datetime, uuid, and Decimal → stringified
  • float("NaN"), float("Infinity") → mapped to safe strings

This improves compatibility with Pydantic deserialization and prevents ValidationError when reading sessions from Redis.


Why is this important?

Previously, using json.dumps(..., default=str) could result in values like "set()" being stored, which causes failures in Session.from_dict() and Event.model_validate(...). This fix prevents such corrupted data and maintains symmetry between to_dict() and the stored Redis payload.


How is it implemented?

  • A custom _json_serializer() function was added to redis_memory_session_service.py.
  • _save_sessions(...) now uses this function via json.dumps(..., default=...).
  • No changes were made outside this file to keep the scope isolated and testable.

@BloodBoy21 BloodBoy21 merged commit 3094b5c into BloodBoy21:feat-redis-session Jul 29, 2025
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.

2 participants