Skip to content

fix(serializer): record class objects as class references - #2127

Open
MaiAditya wants to merge 1 commit into
langfuse:mainfrom
MaiAditya:fix/serializer-class-objects
Open

MaiAditya wants to merge 1 commit into
langfuse:mainfrom
MaiAditya:fix/serializer-class-objects

Conversation

@MaiAditya

@MaiAditya MaiAditya commented Nov 12, 2026 •

Copy link
Copy Markdown

What does this PR do?

Fixes langfuse/langfuse#20157

EventSerializer now returns <class 'module.QualName'> for class objects instead of dumping their namespace (mappingproxy / descriptor entries) or falling back to a double-quoted string. This is what an @observe-decorated function records for arguments like schema=Invoice. The class check sits after the plain JSON types and before the depth, dataclass, BaseModel, __slots__ and vars() branches; those only handle instances, so nothing else changes. The name is built from __module__ and __qualname__ rather than repr() so a metaclass __repr__ (e.g. Enum classes) can't change it.

It also removes the embedded quotes from the final fallback in default(): the value was "\"<not serializable object of type: X>\"" in the JSON. The encode() fallback, which produces the whole document, keeps its quotes.

Not covered: generic aliases and unions such as list[Invoice] or Invoice | None are not type instances and still go through the existing branches; happy to handle them here or in a follow-up.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Refactor
  • Documentation update
  • Tooling, CI, or repo maintenance

Verification

List the main commands you ran:

pytest tests/unit/test_serializer.py tests/unit/test_observe.py   # 72 passed; the 7 new tests fail on main
pytest -n auto tests/unit   # no new failures vs main (prompt/version tests need an installed package and env in my setup)
ruff format --check . && ruff check .
mypy langfuse

Checklist

  • I self-reviewed the diff using code_review.md.
  • I added or updated tests for behavior changes.
  • I updated docs, examples, or .env.template if needed.
  • I did not hand-edit generated files; if generated files changed, I used the upstream regeneration path.
  • I did not commit secrets or credentials.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no actionable issues were found.

Summary

EventSerializer now records class objects as <class 'module.QualName'> instead of walking their fields.

  • Observed class arguments appear as readable class references.
  • Nested serialization failures leave out extra quote characters.

Reviews (2) · Last reviewed commit: "fix(serializer): record class objects as..." · Reviewed by Greptile

A class passed as a value, such as a pydantic model given as an output
schema, fell through to the instance branches. Pydantic classes dumped
their slot descriptors, plain classes dumped their namespace, and
dataclass classes failed in asdict(). Return "<class 'module.QualName'>"
for any class object instead.

The failure fallback in default() also returned a string with embedded
quotes, which were then JSON-escaped a second time. Drop them; encode()
keeps its quotes because its return value is the final JSON.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@CLAassistant

CLAassistant commented Nov 12, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(sdk-python): class objects passed as values are recorded as a dump of the class namespace

2 participants