Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger a DAG Run via the Stable REST API fails with Bad Request due to external_trigger is set #13740

Closed
seybi87 opened this issue Jan 18, 2021 · 7 comments
Labels
affected_version:2.0 Issues Reported for 2.0 area:CLI kind:bug This is a clearly a bug

Comments

@seybi87
Copy link

seybi87 commented Jan 18, 2021

Apache Airflow version:

2.0.0

Environment:

  • Cloud provider or hardware configuration: OpenStack -> VM -> Docker container
  • OS (e.g. from /etc/os-release): Debian GNU/Linux 10 (buster)
  • Kernel (e.g. uname -a): Linux 77f8efd77516 4.4.0-193-generic PrestoToMySqlTransfer #224-Ubuntu

What happened:

I am trying to trigger a DAG run via the new stable REST-API 1.0.0 by using a Java-based client. The Java client is generated from the Airflow OpenAPI specification with OpenAPI generator version 5.0.0 .

In Airflow I have one active DAG demo

I trigger the DAG execution via the java client with the following code snippet:

ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("http://1.2.3.4:8080/api/v1);
DagRunApi dagRunApi = new DagRunApi(defaultClient);
DAGRun dagRun = new DAGRun();
try {
      DAGRun result = dagRunApi.postDagRun("demo", dagRun);

      LOGGER.debug(result);

    } catch (ApiException e) {
      e.printStackTrace();
    }

However, I receive the following exception:

BAD REQUEST

What you expected to happen:

By checking the airflow logs it turned out that the external_trigger value of the DAGRun is set but this is actually a read-only value and not allowed to be set which results in the BAD REQUEST response.

Adding the nullable: true setting to the external_trigger and recreating the java client resolved the issue!

external_trigger:
          type: boolean
          nullable: true
          readOnly: true

How to reproduce it:

Create the Java client (probably any client will produce this error) via OpenAPI generator:

  1. java -jar codegen/openapi-generator-cli-5.0.0.jar generate -i openapi.yaml -g java -o .
  2. create a simple java class and apply the code snippets from above
@kaxil
Copy link
Member

kaxil commented Jan 21, 2021

Not sure why it is giving you error, the default value is True:

external_trigger = auto_field(default=True, dump_only=True)

external_trigger:
type: boolean
default: true
readOnly: true

cc @ephraimbuddy @mik-laj

@seybi87
Copy link
Author

seybi87 commented Jan 21, 2021

The issues is caused because the external_trigger property is defined with default: true .
This results in an object DAGRun dagRun = new DAGRun(); that has set the external_trigger value yet the Airflow server API only accepts null values (as specified for the other DAGRun properties).

@mik-laj
Copy link
Member

mik-laj commented Jan 21, 2021

@kaxil This looks like an error in the generator. This field is marked read-only and should never be sent for POST requests in the request body. This should be fixed in the generator, not in the specification.

@kaxil
Copy link
Member

kaxil commented Jan 21, 2021

@seybi87 Like @mik-laj said -- it looks like an error in generator as we already mark the field readOnly so we don't expect a value for it

@mik-laj
Copy link
Member

mik-laj commented Jan 21, 2021

OpenAPITools/openapi-generator#4190
It looks related.

@seybi87
Copy link
Author

seybi87 commented Jan 21, 2021

Yes, you are right, this should be handled by the generator. So feel free to close this issue.

Just out of curiosity, did you test the postDagRun call with the Airflow go client?

This would show if the error only occurs for the java client parts of code generator or for different languages.

@mik-laj
Copy link
Member

mik-laj commented Jan 21, 2021

Just out of curiosity, did you test the postDagRun call with the Airflow go client?

@houqp Can you check it?

@mik-laj mik-laj closed this as completed Jan 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affected_version:2.0 Issues Reported for 2.0 area:CLI kind:bug This is a clearly a bug
Projects
None yet
Development

No branches or pull requests

4 participants