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

fix: EmrServerlessStartJobOperator not serializing DAGs correctly whe… #38022

Merged
merged 1 commit into from
Mar 25, 2024

Conversation

jliu0812
Copy link
Contributor

@jliu0812 jliu0812 commented Mar 11, 2024

This fixes: #38005

Result: Now EMRServerlessStartJobOperator is able to utilize partial/expand functionality of Airflow.

Previously, the following DAG code will fail to serialize in the webserver:

from datetime import datetime
from airflow.models.dag import DAG
from airflow.providers.amazon.aws.operators.emr import (
    EmrServerlessStartJobOperator,
)

DAG_ID = "example_emr_serverless"
emr_serverless_app_id = "01234abcd"
role_arn = "arn:test"


with DAG(
    dag_id=DAG_ID,
    schedule="@once",
    start_date=datetime(2021, 1, 1),
    tags=["example"],
    catchup=False,
):
    start_job = EmrServerlessStartJobOperator.partial(
        task_id="start_emr_serverless_job",
        application_id=emr_serverless_app_id,
        execution_role_arn=role_arn,
        configuration_overrides={
            "monitoringConfiguration": {"s3MonitoringConfiguration": {"logUri": f"s3://test/logs"}}
        },
    ).expand(
        job_driver=[{
            "sparkSubmit": {
                "entryPoint": "test.jar",
                "entryPointArguments": ["--arg", "1"],
                "sparkSubmitParameters": "--conf sample",
            }
        },{
            "sparkSubmit": {
                "entryPoint": "test.jar",
                "entryPointArguments": ["--arg", "2"],
                "sparkSubmitParameters": "--conf sample",
            }
        }]
    )

After this PR, the above DAG should be serialized successfully.

Copy link

boring-cyborg bot commented Mar 11, 2024

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our pre-commits will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: [email protected]
    Slack: https://s.apache.org/airflow-slack

Copy link
Contributor

@Taragolis Taragolis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is looks fine, however I would rather get rid of conditional Extra Link which implemented by the propery method. It has a bugs into the BatchOperator into the past, and now it happen into the EmrServerlessStartJobOperator

Better link would be grey-out rather than every time try to fix it. But it could be done into the separate PR.

Copy link
Contributor

@ferruzzi ferruzzi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like there has got to be a cleaner way to do this and I came up with a couple alternatives, but none that are significantly better. I'll approve, but hopefully someone comes up with a DRYer solution.

@jliu0812 jliu0812 force-pushed the fix-emrserverless-job-operator branch 2 times, most recently from 97948a4 to d0e30b4 Compare March 11, 2024 19:35
@Taragolis
Copy link
Contributor

comes up with a DRYer solution.

class AwesomeOperator:
    operator_extra_links = (Link1(), Link2(),)

@jliu0812 jliu0812 force-pushed the fix-emrserverless-job-operator branch 3 times, most recently from 845faeb to 442ce77 Compare March 20, 2024 22:08
@jliu0812 jliu0812 force-pushed the fix-emrserverless-job-operator branch from 442ce77 to 95fd866 Compare March 21, 2024 02:01
@ferruzzi ferruzzi merged commit ff28969 into apache:main Mar 25, 2024
46 checks passed
utkarsharma2 pushed a commit to astronomer/airflow that referenced this pull request Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:providers provider:amazon-aws AWS/Amazon - related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EMRServerlessStartJobOperator Expand/Expand Kwargs not Serializing properly
6 participants