fix(serializer): handle single-string __slots__ and detect cycles in slotted objects
Los mantenedores suelen responder en 1 día
Evaluación
Este issue todavía no se ha evaluado.
Descripción
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__).
- Lenguaje dominante
- Python
- Estrellas
- 500
- Forks
- 367
- Merge medio
- 16 h 18 min
- PR fusionados (30 d)
- 51
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de langfuse/langfuse-python
-
tests/unit/test_prompt.py fails on a fresh clone without LANGFUSE_* env varsPosiblemente ocupada @Mathoholic la tomó hace 6 días. Abiertobug feat-prompt-management sdk-python
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
langfuse/langfuse-python#1976 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
bug(langchain): failed streaming LLM runs retain IDs in callback memoPosiblemente ocupada @hassiebp la tomó hace 7 días. Abiertobug integration-langchain sdk-python
langfuse/langfuse-python#1977 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
bug: ChatPromptClient.compile appends str(whole list) once per non-dict placeholder itemPosiblemente ocupada @hassiebp la tomó hace 8 días. Abiertobug feat-prompt-management sdk-python
langfuse/langfuse-python#1971 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
bug: GCS upload detection in MediaManager uses substring match on the full URLPosiblemente ocupada @hassiebp la tomó hace 17 días. Abiertobug feat-multimodal-media sdk-python
langfuse/langfuse-python#1913 · 1 comentario · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
mask is not applied to create_dataset_item or create_score(comment=)Posiblemente ocupada @hassiebp la tomó hace 25 días. Abiertobug compliance feat-data-masking sdk-python security
langfuse/langfuse-python#1896 · 1 comentario · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de langfuse/langfuse-python
Issues similares
-
Custom provider API keys collide on one host: env slot keyed on host:port only, not URL pathAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
NousResearch/hermes-agent#140958 ·
Los mantenedores suelen responder en 1 día
-
Bisect issue233186Abiertobisect
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
dtcxzyw/llvm-bisect-service#548 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
sallowayma-git/IELTS-practice#248 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 65/100
anthropics/claude-plugins-official#6763 · 10 comentarios · 10 reacciones ·
Los mantenedores suelen responder en 3 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día