Azure / azure-sdk-for-python

This repository is for active development of the Azure SDK for Python. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/python/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-python.
MIT License
4.56k stars 2.78k forks source link

[Mgmt] model serialization error for `x-ms-client-flatten` #31575

Open msyyc opened 1 year ago

msyyc commented 1 year ago

subscription_id = "" credential = DefaultAzureCredential() data_factory_name = ""

adf_client = DataFactoryManagementClient(credential, subscription_id) dataset_name = "test_dataset" dataset = { "properties": { "type": "AzureSqlTable", "schema": "xxx" } }

serialization = adf_client.datasets._serialize.body(dataset, "DatasetResource") print(serialization)

- Expected result:
Same with input
- Actual result:
There is additinal `schema` in inner structure.
```python
dataset = {
    "properties": {
        "type": "AzureSqlTable",
        "schema": "xxx",
        "typeProperties": {"schema": "xxx"},  # unexpected `schema`
    }
}
msyyc commented 1 year ago

The root cause is last_rest_key_case_insensitive_extractorimage

If we remove it from key_extractors, the bug is fixed. But according to function description, the extractor is by design. So add @lmazuel for more context.

lmazuel commented 1 year ago

First, the Swagger is broken, as it defines multiple schema as the same level. Honestly, we should have a Swagger linter error to refuse this Swagger. M4 is nice and rename the inner one schema_type_properties_schema, but it's still messed up Swagger.

Details:

This means that AzureSqlTableDataset contains two schema properties at the same level conceptually.

The problem here, is that when receiving a dict, msrest tries to first rebuild a model, and then re-serialize this model. When rebuilding the model, it introspects into key that looks like attribute, and find two schema.

Long story short, this problem wouldn't occur from model directly, it's only happening with the dict syntax. The fix is not obvious, and may not be possible, because we're already in an ambiguous place with this Swagger. I'll take a look when I can.