apache/airflow-client-python

trigger dag api is broken

msumit opened this issue · 10 comments

Client version: 2.1.0

Code:

    dag_id = "example_bash_operator"
    dag_run_api_instance = dag_run_api.DAGRunApi(api_client)
    try:
        # Create a DAGRun object
        dag_run = DAGRun(
            dag_run_id='some_test_run',
            dag_id=dag_id,
            external_trigger=True,
        )
        api_response = dag_run_api_instance.post_dag_run(dag_id, dag_run)
        pprint(api_response)
    except airflow_client.client.exceptions.OpenApiException as e:
        print("Exception when calling DAGRunAPI->post_dag_run: %s\n" % e)

Error:

HTTP response body: {
  "detail": "Property is read-only - 'dag_id'",
  "status": 400,
  "title": "Bad Request",
  "type": "http://apache-airflow-docs.s3-website.eu-central-1.amazonaws.com/docs/apache-airflow/latest/stable-rest-api-ref.html#section/Errors/BadRequest"
}

I encountered the same problem.
and I found the test case (airflow_client/test/test_dag_run_api.py) is just shell, with empty test function.
so I think the quality cannot be assured currently.
mybe using raw REST API is a good choice.

Same problem. It seems you must provide a dag_id to initialize a DAGRun while it gives this read-only error in post_dag_run.

Same problem here after following https://github.com/apache/airflow-client-python/blob/master/airflow_client/docs/DAGRunApi.md#post_dag_run.
DAGRun requires dag_id in its constructor, but if you provide one the post_dag_run will give the Property is read-only error.
So basically it's not possible to start dagruns using the client.

airflow-client-python.git rev bf439f3
Airflow 2.2.0

Probably caused by #4

I have worked around this by re-generating the api client for airflow 2.3.0 with this patch applied. Available from my fork. You can install it in a requirements.txt via:

# apache-airflow-client==2.1.0
-e git://github.com/christhekeele/airflow-client-python.git@2.3.0#egg=apache-airflow-client

Is there any alternate way to trigger task without this client?

Is there any alternate way to trigger task without this client?

https://airflow.apache.org/docs/apache-airflow/2.2.4/stable-rest-api-ref.html

POST /api/v1/dags/{dag_id}/dagRuns

{
  "conf": {},
  "dag_run_id": "test-1",
  "logical_date": "2022-05-25T07:12:59.305Z",
  "state": "queued"
}

results in below error.

{
    "detail": "Property is read-only - 'state'",
    "status": 400,
    "title": "Bad Request",
    "type": "https://airflow.apache.org/docs/apache-airflow/2.2.3/stable-rest-api-ref.html#section/Errors/BadRequest"
}

without "state" param in the payload works 👍

you can not pass dag_id and external_trigger as part of DagRun ( dag_id is passed in post_dag_run() function)
The following worked for me,

dag_run = DAGRun(
            dag_run_id='some_test_run',
            conf={"key":"values"}
            )
api_response = dag_run_api_instance.post_dag_run(dag_id, dag_run)

dag_id, state and external_trigger are now read only. They should not be provided in the DagRun object. With the latest client (2.5.1) we can trigger dag runs like this:

    # DagRun
    dag_run_api_instance = dag_run_api.DAGRunApi(api_client)
    try:
        api_response = dag_run_api_instance.post_dag_run(
            "25616-bug", dag_run_api.DAGRun(dag_run_id="run_from_python_api_client")
        )
        pprint(api_response)
    except airflow_client.client.OpenApiException as e:
        print("Exception when calling DagRunApi->post_dag_run: %s\n" % e)

image

Closing for now, feel free to reopen if needed.