Repository navigation
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
fad3e84 to
f285566
Compare
|
CLA is green now: |
|
Thanks for your interest in Genkit. We're closing this pull request because we can't accept it in its current form. If you'd like to contribute, please start a discussion with the maintainers on an issue first; see CONTRIBUTING.md. |
Fixes #80.
Problem
to_json_attronly checkedisinstance(value, BaseModel)at the top level, so anything that held models —list[Reservation],dict[str, Reservation]— went through plainjson.dumps(value), raisedTypeError, and fell back tostr(value):Input/output span attributes that are documented to be JSON were then unparseable by any consumer.
Change
json.dumpsnow takes adefaulthandler that encodes the leftover leaf withpydantic_core.to_jsonable_python(..., by_alias=True, exclude_none=True, bytes_mode='base64', fallback=str)— the same encodinggenkit-oteluses in_encode_json_value(from #39). Nested models, datetimes, UUIDs, bytes and dataclasses all land as JSON scalars instead of a repr.The top-level
BaseModelfast path is untouched (model_dump_json, alias +exclude_none), andstr(value)is still the last resort.Tests
New
packages/genkit/tests/genkit/core/to_json_attr_test.py, five cases:{'bookings': [Reservation(partySize=2)]}{"bookings": [{"partySize": 2}]}(alias kept,notes=Nonedropped)[Reservation(partySize=3, notes='window')]{"partySize":4}{'at': datetime(...)}{'weird': object()}