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 dbt project parsing/Airflow DAG rendering for load_method=LoadMode.CUSTOM #561

Closed
1 task
tatiana opened this issue Sep 27, 2023 · 3 comments · Fixed by #563
Closed
1 task

Fix dbt project parsing/Airflow DAG rendering for load_method=LoadMode.CUSTOM #561

tatiana opened this issue Sep 27, 2023 · 3 comments · Fixed by #563
Assignees
Milestone

Comments

@tatiana
Copy link
Collaborator

tatiana commented Sep 27, 2023

As part of testing for the 1.1.2 release (#560), we realised that if the DAG uses load_method=LoadMode.CUSTOM, all the test nodes are removed from the DAG.

Example DAG, run from the Cosmos repo (dev/dags):

import os
from datetime import datetime
from pathlib import Path

from cosmos.constants import LoadMode
from cosmos import DbtDag, ProjectConfig, ProfileConfig, RenderConfig
from cosmos.profiles import PostgresUserPasswordProfileMapping

DEFAULT_DBT_ROOT_PATH = Path(__file__).parent / "dbt"
DBT_ROOT_PATH = Path(os.getenv("DBT_ROOT_PATH", DEFAULT_DBT_ROOT_PATH))

profile_config = ProfileConfig(
    profile_name="default",
    target_name="dev",
    profile_mapping=PostgresUserPasswordProfileMapping(
        conn_id="airflow_db",
        profile_args={"schema": "public"},
    ),
)

basic_cosmos_dag = DbtDag(
    # dbt/cosmos-specific parameters
    project_config=ProjectConfig(
        DBT_ROOT_PATH / "jaffle_shop",
    ),
    render_config=RenderConfig(
        load_method=LoadMode.CUSTOM,
    ),
    profile_config=profile_config,
    operator_args={"install_deps": True},
    # normal dag parameters
    schedule_interval="@daily",
    start_date=datetime(2023, 1, 1),
    catchup=False,
    dag_id="basic_cosmos_dag",
)

Rendered DAG with load_method=LoadMode.DBT_LS:
Screenshot 2023-09-27 at 16 32 20

Same DAG rendered with load_method=LoadMode.CUSTOM:
Screenshot 2023-09-27 at 16 41 33

This issue is a bug in the current implementation of Cosmos custom parsing of dbt projects, highlighted since we introduced #543.

Acceptance criteria

  • The aforementioned DAG should render test nodes when using load_method=LoadMode.CUSTOM
@tatiana tatiana added this to the 1.2.0 milestone Sep 27, 2023
@tatiana tatiana mentioned this issue Sep 27, 2023
@raffifu
Copy link
Contributor

raffifu commented Sep 27, 2023

This issue happen because the implementaion of DbtProject not properly parsing the test, as far as i know the only way for custom parser to get the test is from reading *.yml file and scan if there's a tests key on the file. As you can see on the snippet below, the function is only implemented to scan yaml and grab the config. I would like to contribute on this issue

def _handle_config_file(self, path: Path) -> None:
"""
Handles a single config file.
"""

@tatiana
Copy link
Collaborator Author

tatiana commented Sep 27, 2023

Thank you very much, @raffifu ! I appreciate your contributions.

This issue has been there for a while, and the fact the coverage in this part of the code is limited certainly didn't help us surface it before.

Please, reach out if you're not able to look into this, and I'll check it out - otherwise, the ticket is yours 🎁

tatiana added a commit that referenced this issue Sep 27, 2023
…st (#543)"

This is a temporary measurement for the 1.1.2 release until #561 is addressed.

This reverts commit d70e6d7.
tatiana added a commit that referenced this issue Sep 27, 2023
tatiana added a commit that referenced this issue Sep 27, 2023
(cherry picked from commit 1483fd4)
(cherry picked from commit 2a28ef1)
tatiana pushed a commit that referenced this issue Sep 28, 2023
…CUSTOM) (#563)

This PR fixes parsing test nodes when using LoadMethod.CUSTOM, since it didn't return any test nodes.
This issue surfaced after #543.

Closes: #561
tatiana added a commit that referenced this issue Sep 28, 2023
…st (#543)"

This is a temporary measurement for the 1.1.2 release until #561 is addressed.

This reverts commit d70e6d7.
tatiana pushed a commit that referenced this issue Sep 28, 2023
…CUSTOM) (#563)

This PR fixes parsing test nodes when using LoadMethod.CUSTOM, since it didn't return any test nodes.
This issue surfaced after #543.

Closes: #561
(cherry picked from commit 0123c3e)
@tatiana
Copy link
Collaborator Author

tatiana commented Oct 13, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants