Skip to content

Commit 7cfb288

Browse files
authored
[Python] Fix for optional properties in flatten model to keep compatibility (#3271)
* Update dependencies * Add changelog .chronus/changes/auto-microsoft-python-fix-optional-properties-2025-11-3-16-16-35.md * Update dependencies (2025-12-03 09:28:16) * Regenerate for typespec-python (2025-12-03 09:33:26) --------- Co-authored-by: AutoPrFromHttpClientPython <AutoPrFromHttpClientPython>
1 parent 21621c9 commit 7cfb288

165 files changed

Lines changed: 822 additions & 170 deletions

File tree

  • .chronus/changes
  • packages
    • autorest.python
    • typespec-python
      • test
        • azure/generated
          • authentication-api-key/authentication/apikey/_utils
          • authentication-http-custom/authentication/http/custom/_utils
          • authentication-oauth2/authentication/oauth2/_utils
          • authentication-union/authentication/union/_utils
          • azure-client-generator-core-access/specs/azure/clientgenerator/core/access/_utils
          • azure-client-generator-core-alternate-type/specs/azure/clientgenerator/core/alternatetype/_utils
          • azure-client-generator-core-api-version-header/client/alternateapiversion/service/header/_utils
          • azure-client-generator-core-api-version-path/client/alternateapiversion/service/path/_utils
          • azure-client-generator-core-api-version-query/client/alternateapiversion/service/query/_utils
          • azure-client-generator-core-client-initialization/specs/azure/clientgenerator/core/clientinitialization/_utils
          • azure-client-generator-core-client-location/specs/azure/clientgenerator/core/clientlocation/_utils
          • azure-client-generator-core-deserialize-empty-string-as-null/specs/azure/clientgenerator/core/emptystring/_utils
          • azure-client-generator-core-flatten-property/specs/azure/clientgenerator/core/flattenproperty/_utils
          • azure-client-generator-core-hierarchy-building/specs/azure/clientgenerator/core/hierarchybuilding/_utils
          • azure-client-generator-core-override/specs/azure/clientgenerator/core/override/_utils
          • azure-client-generator-core-usage/specs/azure/clientgenerator/core/usage/_utils
          • azure-core-basic/specs/azure/core/basic/_utils
          • azure-core-lro-rpc/specs/azure/core/lro/rpc/_utils
          • azure-core-lro-standard/specs/azure/core/lro/standard/_utils
          • azure-core-model/specs/azure/core/model/_utils
          • azure-core-page/specs/azure/core/page/_utils
          • azure-core-scalar/specs/azure/core/scalar/_utils
          • azure-core-traits/specs/azure/core/traits/_utils
          • azure-encode-duration/specs/azure/encode/duration/_utils
          • azure-example-basic/specs/azure/example/basic/_utils
          • azure-payload-pageable/specs/azure/payload/pageable/_utils
          • azure-resource-manager-common-properties/azure/resourcemanager/commonproperties/_utils
          • azure-resource-manager-large-header/azure/resourcemanager/largeheader/_utils
          • azure-resource-manager-method-subscription-id/azure/resourcemanager/methodsubscriptionid/_utils
          • azure-resource-manager-non-resource/azure/resourcemanager/nonresource/_utils
          • azure-resource-manager-operation-templates/azure/resourcemanager/operationtemplates/_utils
          • azure-resource-manager-resources/azure/resourcemanager/resources/_utils
          • azure-special-headers-client-request-id/azure/specialheaders/xmsclientrequestid/_utils
          • azure-versioning-previewversion/specs/azure/versioning/previewversion/_utils
          • client-namespace/client/clientnamespace
          • client-naming-enum-conflict/client/naming/enumconflict/_utils
          • client-naming/client/naming/main/_utils
          • client-overload/client/overload/_utils
          • client-structure-clientoperationgroup/client/structure/clientoperationgroup/_utils
          • client-structure-default/client/structure/service/_utils
          • client-structure-multiclient/client/structure/multiclient/_utils
          • client-structure-renamedoperation/client/structure/renamedoperation/_utils
          • client-structure-twooperationgroup/client/structure/twooperationgroup/_utils
          • encode-bytes/encode/bytes/_utils
          • encode-datetime/encode/datetime/_utils
          • encode-duration/encode/duration/_utils
          • encode-numeric/encode/numeric/_utils
          • generation-subdir/generation/subdir/_generated/_utils
          • headasbooleanfalse/headasbooleanfalse/_utils
          • headasbooleantrue/headasbooleantrue/_utils
          • parameters-basic/parameters/basic/_utils
          • parameters-body-optionality/parameters/bodyoptionality/_utils
          • parameters-collection-format/parameters/collectionformat/_utils
          • parameters-path/parameters/path/_utils
          • parameters-spread/parameters/spread/_utils
          • payload-content-negotiation/payload/contentnegotiation/_utils
          • payload-json-merge-patch/payload/jsonmergepatch/_utils
          • payload-media-type/payload/mediatype/_utils
          • payload-multipart/payload/multipart/_utils
          • payload-pageable/payload/pageable/_utils
          • payload-xml/payload/xml/_utils
          • resiliency-srv-driven1/resiliency/srv/driven1/_utils
          • resiliency-srv-driven2/resiliency/srv/driven2/_utils
          • response-status-code-range/response/statuscoderange/_utils
          • routes/routes/_utils
          • serialization-encoded-name-json/serialization/encodedname/json/_utils
          • server-endpoint-not-defined/server/endpoint/notdefined/_utils
          • server-path-multiple/server/path/multiple/_utils
          • server-path-single/server/path/single/_utils
          • server-versions-not-versioned/server/versions/notversioned/_utils
          • server-versions-versioned/server/versions/versioned/_utils
          • setuppy-authentication-union/setuppy/authentication/union/_utils
          • special-headers-conditional-request/specialheaders/conditionalrequest/_utils
          • special-headers-repeatability/specialheaders/repeatability/_utils
          • special-words/specialwords/_utils
          • streaming-jsonl/streaming/jsonl/_utils
          • typetest-array/typetest/array/_utils
          • typetest-dictionary/typetest/dictionary/_utils
          • typetest-enum-extensible/typetest/enum/extensible/_utils
          • typetest-enum-fixed/typetest/enum/fixed/_utils
          • typetest-model-empty/typetest/model/empty/_utils
          • typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_utils
          • typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_utils
          • typetest-model-notdiscriminated/typetest/model/notdiscriminated/_utils
          • typetest-model-recursive/typetest/model/recursive/_utils
          • typetest-model-singlediscriminator/typetest/model/singlediscriminator/_utils
          • typetest-model-usage/typetest/model/usage/_utils
          • typetest-model-visibility/typetest/model/visibility/_utils
          • typetest-property-additionalproperties/typetest/property/additionalproperties/_utils
          • typetest-property-nullable/typetest/property/nullable/_utils
          • typetest-property-optional/typetest/property/optional/_utils
          • typetest-property-valuetypes/typetest/property/valuetypes/_utils
          • typetest-scalar/typetest/scalar/_utils
          • typetest-union/typetest/union/_utils
          • versioning-added/versioning/added/_utils
          • versioning-madeoptional/versioning/madeoptional/_utils
          • versioning-removed/versioning/removed/_utils
          • versioning-renamedfrom/versioning/renamedfrom/_utils
          • versioning-returntypechangedfrom/versioning/returntypechangedfrom/_utils
          • versioning-typechangedfrom/versioning/typechangedfrom/_utils
        • unbranded/generated

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
changeKind: fix
3+
packages:
4+
- "@autorest/python"
5+
- "@azure-tools/typespec-python"
6+
---
7+
8+
Fix for optional properties in flatten model to keep compatibility

packages/autorest.python/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
},
3030
"homepage": "https://github.com/Azure/autorest.python/blob/main/README.md",
3131
"dependencies": {
32-
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTYyNzAzNy9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.21.0.tgz",
32+
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTYzMTg5My9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.21.0.tgz",
3333
"@autorest/system-requirements": "~1.0.2",
3434
"fs-extra": "~11.2.0",
3535
"tsx": "~4.19.1"

packages/typespec-python/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"js-yaml": "~4.1.0",
6868
"semver": "~7.6.2",
6969
"tsx": "~4.19.1",
70-
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTYyNzAzNy9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.21.0.tgz",
70+
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTYzMTg5My9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.21.0.tgz",
7171
"fs-extra": "~11.2.0"
7272
},
7373
"devDependencies": {

packages/typespec-python/test/azure/generated/authentication-api-key/authentication/apikey/_utils/model_base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,11 @@ def __init__(
998998

999999
@property
10001000
def _class_type(self) -> typing.Any:
1001-
return getattr(self._type, "args", [None])[0]
1001+
result = getattr(self._type, "args", [None])[0]
1002+
# type may be wrapped by nested functools.partial so we need to check for that
1003+
if isinstance(result, functools.partial):
1004+
return getattr(result, "args", [None])[0]
1005+
return result
10021006

10031007
@property
10041008
def _rest_name(self) -> str:

packages/typespec-python/test/azure/generated/authentication-http-custom/authentication/http/custom/_utils/model_base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,11 @@ def __init__(
998998

999999
@property
10001000
def _class_type(self) -> typing.Any:
1001-
return getattr(self._type, "args", [None])[0]
1001+
result = getattr(self._type, "args", [None])[0]
1002+
# type may be wrapped by nested functools.partial so we need to check for that
1003+
if isinstance(result, functools.partial):
1004+
return getattr(result, "args", [None])[0]
1005+
return result
10021006

10031007
@property
10041008
def _rest_name(self) -> str:

packages/typespec-python/test/azure/generated/authentication-oauth2/authentication/oauth2/_utils/model_base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,11 @@ def __init__(
998998

999999
@property
10001000
def _class_type(self) -> typing.Any:
1001-
return getattr(self._type, "args", [None])[0]
1001+
result = getattr(self._type, "args", [None])[0]
1002+
# type may be wrapped by nested functools.partial so we need to check for that
1003+
if isinstance(result, functools.partial):
1004+
return getattr(result, "args", [None])[0]
1005+
return result
10021006

10031007
@property
10041008
def _rest_name(self) -> str:

packages/typespec-python/test/azure/generated/authentication-union/authentication/union/_utils/model_base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,11 @@ def __init__(
998998

999999
@property
10001000
def _class_type(self) -> typing.Any:
1001-
return getattr(self._type, "args", [None])[0]
1001+
result = getattr(self._type, "args", [None])[0]
1002+
# type may be wrapped by nested functools.partial so we need to check for that
1003+
if isinstance(result, functools.partial):
1004+
return getattr(result, "args", [None])[0]
1005+
return result
10021006

10031007
@property
10041008
def _rest_name(self) -> str:

packages/typespec-python/test/azure/generated/azure-client-generator-core-access/specs/azure/clientgenerator/core/access/_utils/model_base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,11 @@ def __init__(
998998

999999
@property
10001000
def _class_type(self) -> typing.Any:
1001-
return getattr(self._type, "args", [None])[0]
1001+
result = getattr(self._type, "args", [None])[0]
1002+
# type may be wrapped by nested functools.partial so we need to check for that
1003+
if isinstance(result, functools.partial):
1004+
return getattr(result, "args", [None])[0]
1005+
return result
10021006

10031007
@property
10041008
def _rest_name(self) -> str:

packages/typespec-python/test/azure/generated/azure-client-generator-core-alternate-type/specs/azure/clientgenerator/core/alternatetype/_utils/model_base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,11 @@ def __init__(
10121012

10131013
@property
10141014
def _class_type(self) -> typing.Any:
1015-
return getattr(self._type, "args", [None])[0]
1015+
result = getattr(self._type, "args", [None])[0]
1016+
# type may be wrapped by nested functools.partial so we need to check for that
1017+
if isinstance(result, functools.partial):
1018+
return getattr(result, "args", [None])[0]
1019+
return result
10161020

10171021
@property
10181022
def _rest_name(self) -> str:

packages/typespec-python/test/azure/generated/azure-client-generator-core-api-version-header/client/alternateapiversion/service/header/_utils/model_base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,11 @@ def __init__(
998998

999999
@property
10001000
def _class_type(self) -> typing.Any:
1001-
return getattr(self._type, "args", [None])[0]
1001+
result = getattr(self._type, "args", [None])[0]
1002+
# type may be wrapped by nested functools.partial so we need to check for that
1003+
if isinstance(result, functools.partial):
1004+
return getattr(result, "args", [None])[0]
1005+
return result
10021006

10031007
@property
10041008
def _rest_name(self) -> str:

0 commit comments

Comments
 (0)