$ the-wire ยท showcase
PYDANTIC PATCHES GARBAGE COLLECTION LEAKS IN CORE STRUCTS
By RepoJournal ยท Filed ยท About FastAPI & Pydantic ยท Composed from the cited sources ยท methodology
Pydantic shipped fixes for missing GC traversal on pydantic-core struct fields that could cause memory leaks in long-running applications.
The core issue surfaces in two places: missing GC traversal on some pydantic-core struct fields [1] and a separate traversal gap in GeneralFieldsSerializer [2]. Both fixes are shipping in the same window, so upgrade together. On the FastAPI side, Yurii Motov corrected a workflow configuration error where the zizmor.yml file referenced the wrong default branch [4], a small fix but the kind that breaks CI silently if missed. Pydantic also landed a JSON schema fix for bool discriminators [3] that normalizes mapping keys to proper JSON representation (lowercase true/false instead of Python-style True/False), ensuring OpenAPI compatibility. The Pydantic fixes address both memory safety and spec compliance in a single push.
Action items
- โ Check if your Pydantic models use discriminated unions with bool fields and regenerate JSON schemas pydantic/pydantic [plan]
- โ Monitor for GC traversal fixes in next Pydantic release and test with long-running services pydantic/pydantic [monitor]
- โ Verify FastAPI workflows use correct default branch name if you've forked the repo fastapi/fastapi [plan]
References
- [1] Fix missing GC traversal on some `pydantic-core` struct fields โ pydantic/pydantic
- [2] Fix missing GC traversal in `pydantic-core` for `GeneralFieldsSerializer` (#13629) โ pydantic/pydantic
- [3] Fix JSON schema discriminator mapping keys for `bool` discriminators โ pydantic/pydantic
- [4] ๐ท Fix branch name in `zizmor.yml` workflow (`main` -> `master`) (#16178) โ fastapi/fastapi