Skip to content

fix: normalize non-string mapping keys in _json_serialize - #4466

Open
feiiiiii5 wants to merge 1 commit into
Arize-ai:mainfrom
feiiiiii5:feiiiiii5/D240
Open

feiiiiii5 wants to merge 1 commit into
Arize-ai:mainfrom
feiiiiii5:feiiiiii5/D240

Conversation

@feiiiiii5

Copy link
Copy Markdown
Contributor

Fixes #4167

_json_serialize() raises TypeError on mappings with tuple, bytes or enum keys. Because get_tool_attributes() calls it during @tracer.tool() span entry, the exception propagates into user code and the decorated function never executes.

Root cause

json.dumps does not route mapping keys through IOValueJSONEncoder.default, so the encoder cannot help with non-JSON key types. PR #4168 (closed unmerged by its author for housekeeping) proposed a fix; PR #2713 only hardens a different helper.

Fix

Normalize mapping keys recursively before json.dumps, stringifying only keys that JSON cannot accept, while preserving nested dicts/lists and all other values for IOValueJSONEncoder. No skipkeys=True, so nothing is silently dropped.

Verification

  • New focused tests: base-red 2 failed / 1 passed with TypeError: keys must be str, int, float, bool or None, not tuple and the decorated body never running.
  • With fix: 3/3 new tests passed. Full suite delta exactly +2 passes / −2 failures on pristine base; 8 remaining failures are pre-existing network/VCR tests, identical on base.
  • ruff format --check clean; ruff check with the repo's known-first-party setting clean.

Keys materialized inside dataclasses/pydantic models by the encoder are not re-normalized (out of scope); pinned CI Python matrix not run.

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

Status: No status

Development

Successfully merging this pull request may close these issues.

_json_serialize raises TypeError for a mapping with non-string keys, so a @tracer.tool(parameters={("a", "b"): 1}) function never runs

1 participant