fix(serializer): handle single-string __slots__ and detect cycles in slotted objects
メンテナーはふだん 1 日以内に返信
評価
この issue はまだ評価されていません。
説明
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__).
- 主要言語
- Python
- スター
- 500
- フォーク
- 367
- 平均マージ
- 16時間 18分
- マージ済み PR(30日)
- 51
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
langfuse/langfuse-python のほかの issue
-
tests/unit/test_prompt.py fails on a fresh clone without LANGFUSE_* env vars対応中かも @Mathoholic が 8 日前に担当しました。 オープンbug feat-prompt-management sdk-python
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
langfuse/langfuse-python#1976 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
bug(langchain): failed streaming LLM runs retain IDs in callback memo対応中かも @hassiebp が 8 日前に担当しました。 オープンbug integration-langchain sdk-python
langfuse/langfuse-python#1977 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
bug: ChatPromptClient.compile appends str(whole list) once per non-dict placeholder item対応中かも @hassiebp が 10 日前に担当しました。 オープンbug feat-prompt-management sdk-python
langfuse/langfuse-python#1971 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
bug: GCS upload detection in MediaManager uses substring match on the full URL対応中かも @hassiebp が 18 日前に担当しました。 オープンbug feat-multimodal-media sdk-python
langfuse/langfuse-python#1913 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
mask is not applied to create_dataset_item or create_score(comment=)対応中かも @hassiebp が 26 日前に担当しました。 オープンbug compliance feat-data-masking sdk-python security
langfuse/langfuse-python#1896 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
langfuse/langfuse-python の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信
-
Status: Triaged Type: Enhancement
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
canonical/craft-store#448 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
good first issue research size:s skill:numerics sub-issue
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
SKaiNET-developers/SKaiNET#1372 ·
メンテナーはふだん 1 日以内に返信
-
debt
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
microsoft/vscode-flake8#601 ·
メンテナーはふだん 1 日以内に返信