langfuse-python icon indicating copy to clipboard operation
langfuse-python copied to clipboard

fix: serialize typing classes assigned to fields

Open lokmeinmatz opened this issue 1 year ago • 1 comments

We had a case where a function input used an lru_cache as attribute, not as a decorator, and lru_cache somewhere internally stores the return type of the function... and typing.Sequence for example has an attribute slots but that is None, so the serialization failed every time.

If someone has a better idea how to catch that or what types should be serialized to, I'd be glad to get input :)

Thanks!


[!IMPORTANT] Fix serialization of typing classes with __slots__ in EventSerializer and add corresponding test.

  • Behavior:
    • In serializer.py, EventSerializer.default() now checks if obj is a type or a generic alias and serializes it as "<obj.__name__>".
    • Handles cases where __slots__ is None to prevent serialization failures.
  • Tests:
    • Adds test_slots_types() in test_serializer.py to verify serialization of typing classes assigned to fields.

This description was created by Ellipsis for 79a79c3ef20f6e1a783fbd9f8b9a695b9d9a445b. It will automatically update as commits are pushed.

lokmeinmatz avatar Oct 12 '24 10:10 lokmeinmatz

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar Oct 12 '24 10:10 CLAassistant

Thanks again for raising this! Closing this as stale / no longer relevant in Python SDK v3. If you continue to see issues, please open a Github issue 👍🏾

hassiebp avatar Jul 15 '25 08:07 hassiebp