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

on DbtTaskGroup creation dag parameter is ignored. #915

Closed
tboutaour opened this issue Apr 18, 2024 · 1 comment
Closed

on DbtTaskGroup creation dag parameter is ignored. #915

tboutaour opened this issue Apr 18, 2024 · 1 comment
Labels
area:parsing Related to parsing DAG/DBT improvement, issues, or fixes parsing:custom Related to custom parsing, like custom DAG parsing, custom DBT parsing, etc

Comments

@tboutaour
Copy link
Contributor

Currently, there is an issue when attempting to create a DbtTaskGroup using the dag parameter directly. However, this limitation can be bypassed using the with statement, where there is no issue.

Functional example:

with DAG(...):
    DbtTaskGroup(...) 

Problematic example:

dag = DAG(...):
DbtTaskGroup(dag=dag...) 

This problem stems from the airflow_kwargs function within converter.py. Although the dag argument is assumed to be present in DbtToAirflowConverter, this parameter is not being passed to the creation of TaskGroup.

I suggest two potential solutions to the problem:

  1. Adjusting the DbtTaskGroup operator to explicitly pass the dag parameter when creating the task group.
  2. Adjusting the behavior of the airflow_kwargs function to ensure that the dag parameter is properly handled when creating the TaskGroup.
Copy link

dosubot bot commented Apr 18, 2024

To address the issue where the dag parameter is ignored when creating a DbtTaskGroup directly, but works within a with statement, consider the following adjustments:

  1. Modify DbtToAirflowConverter: Ensure the dag parameter is explicitly passed to the TaskGroup during its creation. This might involve revising the logic in the build_airflow_graph function within the DbtToAirflowConverter class to correctly associate the dag with the TaskGroup.

  2. Adjust airflow_kwargs Function: Update the airflow_kwargs function to correctly include the dag parameter in its output. This function should filter kwargs for those specific to Airflow's DAG or TaskGroup initialization methods, ensuring dag is recognized as a valid keyword argument and not removed by the filtering logic.

def airflow_kwargs(**kwargs):
    """
    Ensure 'dag' parameter is correctly handled.
    """
    new_kwargs = {}
    for arg_key, arg_value in kwargs.items():
        if arg_key == 'dag':  # Explicitly include 'dag'
            new_kwargs[arg_key] = arg_value
    return new_kwargs
  1. Review TaskGroup Creation Logic: In the DbtToAirflowConverter, where TaskGroups are created, make sure the dag parameter is explicitly passed if available. This ensures that the TaskGroup is correctly linked to the DAG.

These adjustments should help in resolving the issue with the dag parameter being ignored when passed directly to the DbtTaskGroup. This approach aligns with ensuring that all necessary parameters are correctly passed and handled within the Airflow DAG and TaskGroup creation process.

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

@dosubot dosubot bot added area:parsing Related to parsing DAG/DBT improvement, issues, or fixes parsing:custom Related to custom parsing, like custom DAG parsing, custom DBT parsing, etc labels Apr 18, 2024
arojasb3 pushed a commit to arojasb3/astronomer-cosmos that referenced this issue Jul 14, 2024
This code fixes the problem that dag parameter cannot be passed as
argument at `DbtTaskGroup`.

Previously,  this would work:
```
with DAG(...):
    DbtTaskGroup(...) 
```

But this would fail:
```
dag = DAG(...)
DbtTaskGroup(dag=dag...) 
```

Both work now.

This change has been made to not affecting
`DbtToAirflowConverter` class at all.

Closes: astronomer#915
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:parsing Related to parsing DAG/DBT improvement, issues, or fixes parsing:custom Related to custom parsing, like custom DAG parsing, custom DBT parsing, etc
Projects
None yet
Development

No branches or pull requests

1 participant