fix(serializer): handle single-string __slots__ and detect cycles in slotted objects
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Describe the bug
In langfuse._utils.serializer.EventSerializer, slotted objects are handled by iterating over obj.__slots__:
if hasattr(obj, "__slots__"):
return {
slot: self.default(getattr(obj, slot, None))
for slot in obj.__slots__
}
Two distinct defects exist in this logic:
-
Single string
__slots__attribute loss:
According to the Python Language Reference (Data Model §3.3.2.4:__slots__),__slots__can be defined as a single string naming a single attribute (e.g.__slots__ = "query"). When__slots__is a string, iterating directly over it yields individual characters (q,u,e,r,y).getattr(obj, "q", None)returnsNone, resulting in{"q": null, "u": null, ...}while the actual attributequeryis lost. -
Missing circular reference detection:
Unlike the__dict__branch which tracksobj_id in self.seento immediately break reference cycles, the__slots__branch lacksself.seenprotection. When slotted objects contain reference cycles, each branch expands down to_MAX_DEPTH = 20, causing redundant recursion and bloated payloads.
To Reproduce
import json
from langfuse._utils.serializer import EventSerializer
# Case 1: Single string slot
class SingleSlot:
__slots__ = "query"
def __init__(self):
self.query = "SELECT 1"
res = json.loads(EventSerializer().encode(SingleSlot()))
print(res)
# Current output: {"q": null, "u": null, "e": null, "r": null, "y": null}
# Expected: {"query": "SELECT 1"}
# Case 2: Self-referential slotted node
class SlotNode:
__slots__ = ("next",)
node = SlotNode()
node.next = node
res = json.loads(EventSerializer().encode(node))
# Current output: recurses 20 layers deep
# Expected: {"next": "SlotNode"}
Proposed Fix
- Normalize string
__slots__to a 1-tuple(obj.__slots__,)ifisinstance(obj.__slots__, str). - Add
self.seentracking withtry...finallyto__slots__(matching__dict__).
- Ngôn ngữ chính
- Python
- Star
- 500
- Fork
- 367
- Merge trung bình
- 16 giờ 18 phút
- Pull request đã merge (30 ngày)
- 51
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của langfuse/langfuse-python
-
tests/unit/test_prompt.py fails on a fresh clone without LANGFUSE_* env varsCó thể đã có người làm @Mathoholic đã nhận 7 ngày trước. Đang mởbug feat-prompt-management sdk-python
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
langfuse/langfuse-python#1976 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug(langchain): failed streaming LLM runs retain IDs in callback memoCó thể đã có người làm @hassiebp đã nhận 7 ngày trước. Đang mởbug integration-langchain sdk-python
langfuse/langfuse-python#1977 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug: ChatPromptClient.compile appends str(whole list) once per non-dict placeholder itemCó thể đã có người làm @hassiebp đã nhận 8 ngày trước. Đang mởbug feat-prompt-management sdk-python
langfuse/langfuse-python#1971 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug: GCS upload detection in MediaManager uses substring match on the full URLCó thể đã có người làm @hassiebp đã nhận 17 ngày trước. Đang mởbug feat-multimodal-media sdk-python
langfuse/langfuse-python#1913 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
mask is not applied to create_dataset_item or create_score(comment=)Có thể đã có người làm @hassiebp đã nhận 25 ngày trước. Đang mởbug compliance feat-data-masking sdk-python security
langfuse/langfuse-python#1896 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của langfuse/langfuse-python
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
[Bug] to_ical lexicographical/default sorting moves URL property between two X-WR- propertiesĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
collective/icalendar#1968 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Deferred from #1869: Complete the companion pytest guardrail update noted in the PR description...Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Custom provider API keys collide on one host: env slot keyed on host:port only, not URL pathĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
NousResearch/hermes-agent#140958 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug triage/confirmed
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 85/100
agentscope-ai/agentscope#3355 ·
Maintainer thường phản hồi trong vòng 2 ngày