$ the-wire · showcase
Pydantic signature honors validate_by_alias, GC checks harden core suite
By RepoJournal · Filed · About FastAPI & Pydantic
Two pydantic changes shipped today: a fix so `__signature__` matches `validate_by_alias=False`, and a test-suite guard that catches missing GC traversal in core validators and serializers.
Pydantic fixes the mismatch between a model's generated `__signature__` and the keyword names `__init__` actually accepts when `validate_by_alias` is `False` [1]. Previously, the signature named the parameter after the alias, which validation rejected, and omitted the field name validation required; now the signature uses the field name, so `inspect.signature(Model)` matches reality [1]. Separately, the pydantic-core test suite now checks GC traversal completeness on every `SchemaValidator` and `SchemaSerializer` construction [2]. Each construction verifies that the Python objects retained from the core schema are reported to the garbage collector, so a field missing from an `impl_py_gc_traverse!()` call fails whichever existing test exercises that schema feature, a defense-in-depth against bugs like #13621 [2]. Both changes are merged into pydantic/pydantic; the signature fix landed as commit 4bc21c0, the GC check as commit f512b08 [3][4].
Action items
- → If you rely on introspection of models with validate_by_alias=False, verify your code against the corrected __signature__ after upgrading to the commit containing #13730. pydantic/pydantic [plan]
- → Watch for upcoming pydantic releases that include the GC traversal check; it may surface previously latent traversal gaps in custom validators/serializers. pydantic/pydantic [monitor]
References
- [1] Use the field name in `__signature__` when `validate_by_alias` is`False` ↗ pydantic/pydantic
- [2] Check GC traversal completeness when constructing validators and serializers in tests ↗ pydantic/pydantic
- [3] Use the field name in `__signature__` when `validate_by_alias` is`False` (#13730) ↗ pydantic/pydantic
- [4] Check GC traversal completeness when constructing validators and serializers in tests (#13626) ↗ pydantic/pydantic