Reputation: 176
I have been following the steps provided by Microsoft to create ADF triggers using python SDK but it is not working.
# 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.
Upvotes: 0
Views: 1323
Reputation: 370
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
Upvotes: 1
Reputation: 1301
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)
Upvotes: 1