azure-sdk-for-python: Bad body serialization creating a Schedule Trigger in Data Factory

  • Package Name: azure-mgmt-datafactory
  • Package Version: 1.1.0
  • Operating System: Windows
  • Python Version: 3.8

Describe the bug Using the library to create a Data Factory trigger, calling DataFactoryManagementClient.triggers.create_or_update method is not serializing the request body correctly

Serialized example:

{
    "type": "ScheduleTrigger",
    "description": "My scheduler trigger",
    "pipelines": [
        {
            "pipelineReference": {
                "type": "PipelineReference",
                "referenceName": "PL_ADW_IMPORT_MASTER"
            },
            "parameters": {
                "datacenter_name": "datacenter1",
                "schedule_name": "schedule1"
            }
        }
    ],
    "typeProperties": {
        "recurrence": {
            "frequency": "Minute",
            "interval": 15,
            "startTime": "2022-12-12T04:00:00.000Z",
            "endTime": "2022-12-12T05:00:00.000Z",
            "timeZone": "UTC"
        }
    }
}

The correct serealized body is:

{
    "properties": {
        "type": "ScheduleTrigger",
        "description": "My scheduler trigger",
        "pipelines": [
            {
                "pipelineReference": {
                    "type": "PipelineReference",
                    "referenceName": "PL_ADW_IMPORT_MASTER"
                },
                "parameters": {
                    "datacenter_name": "datacenter1",
                    "schedule_name": "schedule1"
                }
            }
        ],
        "typeProperties": {
            "recurrence": {
                "frequency": "Minute",
                "interval": 15,
                "startTime": "2022-12-12T04:00:00.000Z",
                "endTime": "2022-12-12T05:00:00.000Z",
                "timeZone": "UTC"
            }
        }
    }
}

To Reproduce Steps to reproduce the behavior:

from azure.identity import DefaultAzureCredential 
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.datafactory import DataFactoryManagementClient
from azure.mgmt.datafactory.models import *



def main():
    credential = DefaultAzureCredential()
    adf_client = DataFactoryManagementClient(credential, 'AAAAA-VVVV-SWESDDS-XCV3-3bb145207'
   
    # Create a trigger
    rg_name = 'EUNPADWCANRSG01'
    df_name = 'EUNPADWCANDFA01'
    tr_name = 'mytrigger'
    scheduler_recurrence = ScheduleTriggerRecurrence(frequency='Minute', interval='15',start_time='2022-12-12T04:00:00Z', end_time='2022-12-12T05:00:00Z', time_zone='UTC')
    pipeline_parameters = {'datacenter_name':'datacenter1', 'schedule_name':'schedule1'}
    pipelines_to_run = []
    pipeline_reference = PipelineReference(reference_name='PL_ADW_IMPORT_MASTER')
    pipelines_to_run.append(TriggerPipelineReference(pipeline_reference=pipeline_reference, parameters=pipeline_parameters))
    tr_properties = ScheduleTrigger(description='My scheduler trigger', pipelines = pipelines_to_run, recurrence=scheduler_recurrence)    
    adf_client.triggers.create_or_update(rg_name, df_name, tr_name, tr_properties)

    # Start the trigger
    adf_client.triggers.start(rg_name, df_name, tr_name)

if __name__ == "__main__":
    main()

Expected behavior Running this code,

\azure\mgmt\datafactory\operations_triggers_operations.py trigger an Exception because the response status code is 400

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 18 (8 by maintainers)

Commits related to this issue

Most upvoted comments

@lrtoyou1223 Looks like the document for trigger in Python doesn’t work as expected, could you please help have a look at this? Thanks!

@csotomon We will check this and update here later, thanks for your patience.

Hi @csotomon I’m closing your PR https://github.com/Azure/azure-sdk-for-python/pull/18963, since this code is auto-generated, meaning we can’t fix the code directly. Fix needs to go in OpenAPI description here: https://github.com/Azure/azure-rest-api-specs/tree/master/specification/datafactory/resource-manager

The ADF team was not tagged correctly in your issue and I’m sorry about that, they are tagged now and hopefully should see it and fix the OpenAPI spec. Feel free to email me at microsoft (my email is the same as github alias) if you don’t see things moving in a few days.

Thanks,