Skip to content

Commit 1382618

Browse files
hassiebpabrasseu
andauthored
fix(serializer): Fix None serialization without langchain installed (#955)
Co-authored-by: Alexandre Brasseur <34026822+abrasseu@users.noreply.github.com>
1 parent 5477d34 commit 1382618

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

langfuse/serializer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def default(self, obj: Any):
7878
return str(obj)
7979

8080
# if langchain is not available, the Serializable type is NoneType
81-
if Serializable is not None and isinstance(obj, Serializable):
81+
if Serializable is not type(None) and isinstance(obj, Serializable):
8282
return obj.to_json()
8383

8484
# 64-bit integers might overflow the JavaScript safe integer range.

tests/test_serializer.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
from pathlib import Path
66
from pydantic import BaseModel
77
import json
8+
import pytest
89
import threading
10+
import langfuse.serializer
911
from langfuse.serializer import (
1012
EventSerializer,
1113
)
@@ -162,6 +164,12 @@ def test_none():
162164
assert serializer.encode(None) == "null"
163165

164166

167+
def test_none_without_langchain(monkeypatch: pytest.MonkeyPatch):
168+
monkeypatch.setattr(langfuse.serializer, "Serializable", type(None), raising=True)
169+
serializer = EventSerializer()
170+
assert serializer.encode(None) == "null"
171+
172+
165173
def test_slots():
166174
class SlotClass:
167175
__slots__ = ["field"]

0 commit comments

Comments
 (0)