Skip to content

fix(schema): harden _schema_short_hash to strict JSON serialization #385

Description

@yeongseon

Context

Split from #379 (was "item B"). This is defensive hardening, not a live regression — schemas always arrive as pure JSON from Pydantic model_json_schema(), so the anonymous-hash path is not reached with non-JSON input in practice. Tracked separately so it does not dilute the JSON-Pointer-safety fix in #379.

_schema_short_hash() (utils.py:144) uses default=str:

canonical = json.dumps(schema, sort_keys=True, default=str)

default=str silently stringifies non-JSON objects. str(obj) may embed a memory address, making InlineSchema_<hash> differ across processes — contradicting the "stable/deterministic hash" docstring — and it masks a violation of the endpoint-metadata contract (schemas must be plain JSON-compatible dicts).

Acceptance Checklist

  • Replace default=str with strict serialization: json.dumps(schema, sort_keys=True, separators=(",", ":")) so non-JSON input raises TypeError loudly instead of producing a non-deterministic name.
  • Test: a non-JSON-serializable schema raises TypeError; identical schemas hash identically.
  • Coverage stays >= 95%.

Out of scope

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority:p2Normal / later

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions