Skip to content

Conversation

@adityuhkapoor
Copy link

Summary

pre_parse_json() uses field_info.annotation is not str to decide
whether to attempt json.loads() on string values. For str | None,
the annotation is not identical to str, so the check passes and
strings like '{"key": "val"}' get parsed into dicts — then rejected
by Pydantic validation.

Replace the identity check with a helper that skips pre-parsing when
the union only contains simple types. Complex unions like
list[str] | None still get pre-parsed.

Closes #1873

Test plan

  • Regression test for str | None preserving JSON strings
  • Verifies complex unions still pre-parse
  • All existing tests pass

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: String parameters starting with digits coerced to numbers, causing UUID data loss

1 participant