Skip to content

[Python] Support patching polymorphic models#9923

Draft
annatisch wants to merge 1 commit intomainfrom
annatisch-patch-1
Draft

[Python] Support patching polymorphic models#9923
annatisch wants to merge 1 commit intomainfrom
annatisch-patch-1

Conversation

@annatisch
Copy link
Member

@annatisch annatisch commented Mar 5, 2026

If a polymorphic model is patched - it wont be deserialized unless it has explicitly been declared with the same discriminator as its parent. This patch intends to automatically infer that discriminator, so that the patched model will replace the original in polymorphic deserialization.

Before:

from ._models import PolyMorphicModel as GeneratedModel

# Unless the original discriminator was specified, this patched model would not be
# used for deserialization.
class ModifiedModel(GeneratedModel, discriminator="fooModel"):
    extra_property: str = "Foo"

After:

from ._models import PolyMorphicModel as GeneratedModel

# The discriminator is now automatically inferred from the inherited model.
class ModifiedModel(GeneratedModel):
    extra_property: str = "Foo"

@microsoft-github-policy-service microsoft-github-policy-service bot added the emitter:client:python Issue for the Python client emitter: @typespec/http-client-python label Mar 5, 2026
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 5, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-python@9923

commit: 71df4db

@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2026

❌ There is undocummented changes. Run chronus add to add a changeset or click here.

The following packages have changes but are not documented.

  • @typespec/http-client-python
Show changes

@azure-sdk
Copy link
Collaborator

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:python Issue for the Python client emitter: @typespec/http-client-python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants