Reputation: 515
I am new to Python and airflow. Trying to implement a sensor as below, and the error says "AttributeError: 'mySensor' object has no attribute 'l'" I had a look at other attribute error questions, but I have no idea where the 'l' in my error comes from. Could someone help shed some light on this? Below is the whole class for mySensor. Many thanks.
class mySensor(SFTPSensor):
"""
Subclass of SFTPSensor to override the poke() method
"""
template_fields = "previous_month"
@apply_defaults
def __init__(self,
last_day_previous_month,
*args,
**kwargs):
self.previous_month = previous_month
super(mySensor, self).__init__(*args, **kwargs)
def poke(self, context):
remote_path = self.path+"file_to_check"+self.previous_month
file_count = len(self.hook.list_directory(remote_path))
if file_count == 0:
return False
else:
logging.info("Found %d files", file_count)
return True
and where I used the Sensor
sensor_task = mySensor(
previous_month=_previous_month_template,
task_id="check-remote-files",
dag=dag,
sftp_conn_id=my_conn_id,
path="/my/path/"
)
Upvotes: 0
Views: 4991
Reputation: 911
I was getting a similar error with an Airflow operator:
AttributeError: 'MyOperator' object has no attribute 't'
To resolve, check that the template_fields
makes sense compared to your __init__
arguments.
You have template_fields = "previous_month"
but in your __init__
there is no such parameter.
In my case, the __init__
and template_fields
did align. However, I had template_fields = ("myfield")
instead of template_fields = ("myfield",)
. The comma must be present.
Upvotes: 6