Skip to content

AttributeError: 'JsonPlusRedisSerializer' object has no attribute '_default' #115

@Sagnnik

Description

@Sagnnik

Problem

I saw the previous fix on JsonPlusRedisSerializer and replaced the dumps function with this:

def dumps(self, obj: Any) -> bytes:
        """Use orjson for serialization with LangChain object support via default handler."""
        # Use orjson with default handler for LangChain objects
        # The _default method from parent class handles LangChain serialization
        return orjson.dumps(obj, default=self._default)

Error : AttributeError: 'JsonPlusRedisSerializer' object has no attribute '_default'
And it is not being inherited from JsonPlusSerializer in langgraph/checkpoint/serde/jsonplus.py either, which I am assuming was the case previously.
These are my dependencies:

dependencies = [
    "langchain>=1.0.3",
    "langchain-community>=0.4.1",
    "langgraph>=1.0.2",
    "langsmith>=0.4.40",
    "msgpack>=1.1.2",
    "redis>=7.0.1",
]

I got this fix which does work from my side:

from langchain_core.messages import BaseMessage
def _default(self, o):
        """Fallback handler for un-serializable orjson objects."""
        if isinstance(o, BaseMessage):
            return {
                "lc": 1,
                "type": "constructor",
                "id": ["langchain", "schema", "messages", o.__class__.__name__],
                "kwargs": o.__dict__,  # or o.dict() if available
            }
        raise TypeError(f"Object of type {type(o)} is not JSON serializable")

If it is not too much of a trouble can the maintainers please look into it

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions