Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

fix(serializer): handle single-string __slots__ and detect cycles in slotted objects

オープン
#2,014 コメント 0 件 リアクション 0 件 担当者 1 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@hassiebp がすでに取り組んでいます。

2026年10月16日 から。

  • #2015 @passionworkeer による — オープン

評価

この issue はまだ評価されていません。

説明

bug sdk-python
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:

  1. 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) returns None, resulting in {"q": null, "u": null, ...} while the actual attribute query is lost.

  2. Missing circular reference detection:
    Unlike the __dict__ branch which tracks obj_id in self.seen to immediately break reference cycles, the __slots__ branch lacks self.seen protection. 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
  1. Normalize string __slots__ to a 1-tuple (obj.__slots__,) if isinstance(obj.__slots__, str).
  2. Add self.seen tracking with try...finally to __slots__ (matching __dict__).
主要言語
Python
スター
500
フォーク
367
平均マージ
16時間 18分
マージ済み PR(30日)
51

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

langfuse/langfuse-python のほかの issue

langfuse/langfuse-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。