fix: fixed json serialization #1
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This PR fixes an issue with the JSON serialization of
Sessionobjects in theRedisMemorySessionService. Specifically, it adds a robust serializer that correctly handles non-JSON-native types such as:set→ converted tolistbytes→ decoded toutf-8or fallback toreprdatetime,uuid, andDecimal→ stringifiedfloat("NaN"),float("Infinity")→ mapped to safe stringsThis improves compatibility with Pydantic deserialization and prevents
ValidationErrorwhen 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 inSession.from_dict()andEvent.model_validate(...). This fix prevents such corrupted data and maintains symmetry betweento_dict()and the stored Redis payload.How is it implemented?
_json_serializer()function was added toredis_memory_session_service.py._save_sessions(...)now uses this function viajson.dumps(..., default=...).