[Python] Fix allOf inheritance by using **kwargs throughout inheritance chain #1393
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
When a child model extends a parent via
allOf, the generated__init__method was consuming parameters from kwargs, preventing them from reaching parent classes. This caused deserialization failures with errors like:ValueError: Invalid value for 'name' (None), must not be 'None'TypeError: Parent.__init__() got an unexpected keyword argument 'child_field'The Problem
Consider this OpenAPI spec with inheritance:
The old generated code had two problems:
Problem 1: Python extracts named parameters from
**kwargsinto local variables, so whenParent.__init__is called, those parameters are no longer in kwargs.Problem 2: Root classes didn't accept
**kwargs, so if a child class has fields the parent doesn't know about, it fails with "unexpected keyword argument".The Fix
For child classes (with parent): Use
**kwargsfor all parameters and extract withkwargs.get():For root classes (without parent): Add
**kwargsto accept extra parameters:This ensures the full kwargs dict flows through the entire inheritance chain, and each class extracts what it needs without breaking the chain.
Test Plan
allOfinheritanceDiagnosis Notes
This bug manifests as errors like:
ValueError: Invalid value for 'property_name' (None), must not be 'None'ValueError: Invalid value for 'property_name' (None), must be one of [...]Repro Notes
🤖 Generated with Claude Code
🧍🏻Manually reviewed and edited by a real human, not just AI slop