You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/01/04 03:56:22 UTC
[GitHub] [airflow] uplsh580 opened a new issue #20646: (Airflow 2.2.3) When Inherit Bashoperator, TypeError: __init__() got an unexpected keyword argument 'default_args'
uplsh580 opened a new issue #20646:
URL: https://github.com/apache/airflow/issues/20646
### Apache Airflow version
2.2.3 (latest released)
### What happened
To customize the operator, I inherited and customized the BashOperator.
It was used well in the previous 2.1.0 version without any problems, but an error occurred in the 2.2.3 version as follows.
```
Broken DAG: [/opt/airflow/dags/test_dag_custom_operator.py] Traceback (most recent call last):
File "/opt/airflow/dags/test_dag_custom_operator.py", line 14, in <module>
t1 = CustomOperator(task_id="date_task", cmd="date")
File "/home/airflow/.local/lib/python3.7/site-packages/airflow/models/baseoperator.py", line 188, in apply_defaults
result = func(self, *args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'default_args'
```
### What you expected to happen
_No response_
### How to reproduce
create DAG file as below.
`custom_operator.py`
``` python
from airflow.operators.bash import BashOperator
class CustomOperator(BashOperator):
def __init__(self, task_id: str, cmd: str):
super().__init__(task_id=task_id, bash_command=cmd)
```
`custom_operator_dag.py`
``` python
from datetime import datetime, timedelta
from airflow import DAG
from custom_operator import CustomOperator
default_args = {"owner": "uplsh", "retries": 1, "retry_delay": timedelta(minutes=1), "xcom_push_flag": True}
with DAG(
"custom_operator",
default_args=default_args,
description="A print date",
schedule_interval=timedelta(seconds=20),
start_date=datetime(2021, 1, 1),
catchup=False,
) as dag:
t1 = CustomOperator(task_id="date_task", cmd="date")
```
### Operating System
centos7.9, MacOS12.1 (It occurs in both environments.)
### Versions of Apache Airflow Providers
apache-airflow-providers-amazon | 2.4.0
apache-airflow-providers-celery | 2.1.0
apache-airflow-providers-cncf-kubernetes | 2.2.0
apache-airflow-providers-docker | 2.3.0
apache-airflow-providers-elasticsearch | 2.1.0
apache-airflow-providers-ftp | 2.0.1
apache-airflow-providers-google | 6.2.0
apache-airflow-providers-grpc | 2.0.1
apache-airflow-providers-hashicorp | 2.1.1
apache-airflow-providers-http | 2.0.1
apache-airflow-providers-imap | 2.0.1
apache-airflow-providers-microsoft-azure | 3.4.0
apache-airflow-providers-mysql | 2.1.1
apache-airflow-providers-odbc | 2.0.1
apache-airflow-providers-postgres | 2.4.0
apache-airflow-providers-redis | 2.0.1
apache-airflow-providers-sendgrid | 2.0.1
apache-airflow-providers-sftp | 2.3.0
apache-airflow-providers-slack | 4.1.0
apache-airflow-providers-sqlite | 2.0.1
apache-airflow-providers-ssh | 2.3.0
### Deployment
Docker-Compose
### Deployment details
_No response_
### Anything else
_No response_
### Are you willing to submit PR?
- [ ] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] uranusjr commented on issue #20646: (Airflow 2.2.3) When Inherit Bashoperator, TypeError: __init__() got an unexpected keyword argument 'default_args'
Posted by GitBox <gi...@apache.org>.
uranusjr commented on issue #20646:
URL: https://github.com/apache/airflow/issues/20646#issuecomment-1004524562
`default_args` is an expected argument on `BaseOperator` (which is the root class for all operator classes), and all operators should also accept it and forward it to `super()`. The common way to do it is by accepting `**kwargs` and pass them as `super().__init__(**kwargs)`. Or to summarise, your custom operator implementation is wrong, and the fact it worked previously is sort of accidental.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] uranusjr closed issue #20646: (Airflow 2.2.3) When Inherit Bashoperator, TypeError: __init__() got an unexpected keyword argument 'default_args'
Posted by GitBox <gi...@apache.org>.
uranusjr closed issue #20646:
URL: https://github.com/apache/airflow/issues/20646
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org