0

I have been following the steps provided by Microsoft to create ADF triggers using python SDK but it is not working.

https://learn.microsoft.com/en-us/azure/data-factory/how-to-create-schedule-trigger?tabs=data-factory#python-sdk

# Create a trigger
    tr_name = 'mytrigger'
    scheduler_recurrence = ScheduleTriggerRecurrence(frequency='Minute', interval='15',start_time='2017-12-12T04:00:00Z', end_time='2017-12-12T05:00:00Z', time_zone='UTC')
    pipeline_parameters = {'inputPath':'adftutorial/input', 'outputPath':'adftutorial/output'}
    pipelines_to_run = []
    pipeline_reference = PipelineReference('copyPipeline')
    pipelines_to_run.append(TriggerPipelineReference(pipeline_reference, 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)

It is throwing the following error. What am I missing?

pipeline_reference = PipelineReference('copyPipeline') TypeError: init() takes 1 positional argument but 2 were given

Thanks for your help.

1
  • We'll need to see the code for PipelineReference(). The error is showing you that you have too many arguments. Remember that every class method has its own instance passed in automatically. In other words, an init method that takes no other arguments still takes one: def __init__(self): ... In order to take in another arugment, the constructor would look something like: def __init__(self, some_argument): ... Commented Sep 13, 2021 at 18:46

2 Answers 2

1

I feel the code and the documentation looks fine, check for the parameters which needs to be passed for PipelineReference

Also, Python passes an argument called “self” into every method in an object. “self” is similar to “this” in JavaScript. The “self” argument stores information about the values in an object.

The “takes 1 positional argument but 2 were given” error is raised when you try to pass an argument through a method in a class without also specifying “self” as an argument.

You solve this error by adding “self” as an argument to all the methods in a class. (In your case Init)

Sign up to request clarification or add additional context in comments.

Comments

1

I had the same error and fixed it by using keyword arguments for PipelineResource and TriggerPipelineReference as follows:

pipeline_reference = PipelineReference(reference_name='copyPipeline')
pipelines_to_run.append(TriggerPipelineReference(pipeline_reference=pipeline_reference, pipeline_parameters))

Also, the data factory SDK (as of this posting) replaced the start function with begin_start as follows:

adf_client.triggers.begin_start(rg_name, df_name, tr_name)

The issue stems from the init function. For example, in the init function for PipelineReference, you will notice the arguments are (self, *, reference_name: str, name: Optional[str] = None, **kwargs)

def __init__(
    self,
    *,
    reference_name: str,
    name: Optional[str] = None,
    **kwargs
):
    """
    :keyword reference_name: Required. Reference pipeline name.
    :paramtype reference_name: str
    :keyword name: Reference name.
    :paramtype name: str
    """
    super(PipelineReference, self).__init__(**kwargs)
    self.reference_name = reference_name
    self.name = name

Per the docs:

Parameters after “*” or “*identifier” are keyword-only parameters and may only be passed by keyword arguments.

The init function for TriggerPipelineReference follows a similar approach except that pipeline_reference is explicity defined as a keyword argument with a default value of None.

def __init__(
    self,
    *,
    pipeline_reference: Optional["PipelineReference"] = None,
    parameters: Optional[Dict[str, Any]] = None,
    **kwargs
):
    """
    :keyword pipeline_reference: Pipeline reference.
    :paramtype pipeline_reference: ~azure.mgmt.datafactory.models.PipelineReference
    :keyword parameters: Pipeline parameters.
    :paramtype parameters: dict[str, any]
    """
    super(TriggerPipelineReference, self).__init__(**kwargs)
    self.pipeline_reference = pipeline_reference
    self.parameters = parameters

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.