Skip to content

Airflow Python Client 2.6.0rc2 fails with read-only dag_id attribute on post_dag_run #75

@potiuk

Description

@potiuk

When running get_tasks API calls, the Python cllient (when used with Airflow 2.6.0) fails with:

Exception when calling DAGRunAPI->post_dag_run: `dag_id` is a read-only attribute. Use `from_openapi_data` to instantiate class with read only attributes.

Apparently because it expects not Nuill execution timeout,.

How to reproduce:

  1. breeze start-airflow --db-reset --use-airflow-version 2.6.0 --load-example-dags --load-default-connections

  2. In the terminal lnstall 2.6.0rc1 of python-client: pip install apache-airflow-client==2.6.0.rc2

  3. Ctrl-C webserver

  4. Change configuration in ~/airflow/airflow.cfg (with vim for example)

  • set [webserver] -> expose_config = True
  • enable basic authentication by adding ,airflow.api.auth.backend.basic_auth to [api] -> auth_backends
  1. run airflow webserver again

  2. Copy the following scripts to the container (for example to files folder to be able to copy it in the host) and name it test_python_client.py:

import airflow_client.client
from pprint import pprint
from airflow_client.client.api import config_api, dag_api, dag_run_api
from airflow_client.client.model.dag_run import DAGRun

configuration = airflow_client.client.Configuration(
    host="http://localhost:8080/api/v1",
    username='admin',
    password='admin'
)

dag_id = "example_bash_operator"

# Enter a context with an instance of the API client
with airflow_client.client.ApiClient(configuration) as api_client:
    # Get current configuration
    conf_api_instance = config_api.ConfigApi(api_client)
    try:
        api_response = conf_api_instance.get_config()
        pprint(api_response)
    except airflow_client.client.OpenApiException as e:
        print("Exception when calling ConfigApi->get_config: %s\n" % e)


    # Get dag list
    dag_api_instance = dag_api.DAGApi(api_client)
    try:
        api_response = dag_api_instance.get_dags()
        pprint(api_response)
    except airflow_client.client.OpenApiException as e:
        print("Exception when calling DagAPI->get_dags: %s\n" % e)

    print("Caling get tasks")
    # Get tasks for a DAG (TODO: issue#20)
    try:
        api_response = dag_api_instance.get_tasks(dag_id)
        pprint(api_response)
    except airflow_client.client.exceptions.OpenApiException as e:
        print("Exception when calling DagAPI->get_tasks: %s\n" % e)


    print("Caling post dag run")
    # Trigger a dag run (TODO: issue#21)
    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)

  1. Run the script

Result: post_dag_run will fail with this error without even attempting to call the API.

Caling post dag run
Exception when calling DAGRunAPI->post_dag_run: `dag_id` is a read-only attribute. Use `from_openapi_data` to instantiate class with read only attributes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions