diff --git a/packages/http-client-python/generator/pygen/codegen/templates/model_base.py.jinja2 b/packages/http-client-python/generator/pygen/codegen/templates/model_base.py.jinja2 index c4c58fe89e5..c3cfc842d53 100644 --- a/packages/http-client-python/generator/pygen/codegen/templates/model_base.py.jinja2 +++ b/packages/http-client-python/generator/pygen/codegen/templates/model_base.py.jinja2 @@ -725,6 +725,10 @@ class Model(_MyMutableMapping): def __init_subclass__(cls, discriminator: typing.Optional[str] = None) -> None: for base in cls.__bases__: if hasattr(base, "__mapping__"): + if discriminator is None: + # This could mean that a ploymorphic model has been patched without an explicit discriminator. + # We will attempt to find and replace its parent in the mapping. + discriminator = next((k for k, v in base.__mapping__.items() if v == base), None) base.__mapping__[discriminator or cls.__name__] = cls # type: ignore {% if code_model.has_padded_model_property %}