-
Notifications
You must be signed in to change notification settings - Fork 297
Add CI job to test multiple dbt versions for the async DAG #1535
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cee5a70
Add CI job to test multiple dbt versions for the async DAG
pankajkoti 3c612aa
Use env variable to get adapter version in DAG
pankajkoti ba3f18d
Add separate test example dag
pankajkoti 513b197
Install specific protobuf version for dbt 1.7 and ignore example dag …
pankajkoti fe20a7f
Address review comments
pankajkoti 9f1a85b
Update .github/workflows/test.yml
pankajkoti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -x | ||
| set -e | ||
|
|
||
| DBT_VERSION="$1" | ||
| echo "DBT_VERSION:" | ||
| echo "$DBT_VERSION" | ||
|
|
||
|
|
||
| pip uninstall dbt-adapters dbt-common dbt-core dbt-extractor dbt-postgres dbt-semantic-interfaces -y | ||
| pip install "dbt-postgres==$DBT_VERSION" "dbt-databricks==$DBT_VERSION" "dbt-bigquery==$DBT_VERSION" | ||
| export SOURCE_RENDERING_BEHAVIOR=all | ||
| rm -rf airflow.*; \ | ||
| airflow db init; \ | ||
|
|
||
| if [ "$DBT_VERSION" = "1.7" ]; then | ||
| # Otherwise, we will get the following error: | ||
| # stderr: MessageToJson() got an unexpected keyword argument 'including_default_value_fields' | ||
| echo "DBT version is 1.7 — Installing protobuf==4.25.6..." | ||
| pip install protobuf==4.25.6 | ||
| fi | ||
|
|
||
| rm -rf dbt/jaffle_shop/dbt_packages; | ||
| pytest -vv \ | ||
| --cov=cosmos \ | ||
| --cov-report=term-missing \ | ||
| --cov-report=xml \ | ||
| "tests/test_async_example_dag.py::test_example_dag[simple_dag_async]" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| # We already have tests/test_example_dags.py, but it doesn’t run against multiple dbt versions in CI. | ||
| # Some dbt versions have shown parsing issues with certain example DAGs — something we may need to address over time. | ||
| # With PR #1535, the goal is to test the async example DAG across multiple dbt versions. To prevent the CI job from | ||
| # failing early due to unrelated DAG parsing errors, PR #1535 introduces this new test_async_example_dag.py file. | ||
| # This file replicates tests/test_example_dags.py but excludes all DAGs except simple_async_dag by adding them to | ||
| # .airflowignore. This ensures the CI job focuses solely on testing simple_async_dag over multiple dbt versions | ||
| # without being disrupted by other DAG parsing issues. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| try: | ||
| from functools import cache | ||
| except ImportError: | ||
| from functools import lru_cache as cache | ||
|
|
||
|
|
||
| import airflow | ||
| import pytest | ||
| from airflow.models.dagbag import DagBag | ||
| from airflow.utils.db import create_default_connections | ||
| from airflow.utils.session import provide_session | ||
| from packaging.version import Version | ||
|
|
||
| EXAMPLE_DAGS_DIR = Path(__file__).parent.parent / "dev/dags" | ||
| ALL_FILES_TO_IGNORE = [ | ||
| f.name for f in EXAMPLE_DAGS_DIR.iterdir() if f.is_file() and f.suffix == ".py" and f.name != "simple_dag_async.py" | ||
| ] | ||
|
|
||
| AIRFLOW_IGNORE_FILE = EXAMPLE_DAGS_DIR / ".airflowignore" | ||
| AIRFLOW_VERSION = Version(airflow.__version__) | ||
|
|
||
|
|
||
| @provide_session | ||
| def get_session(session=None): | ||
| create_default_connections(session) | ||
| return session | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| def session(): | ||
| return get_session() | ||
|
|
||
|
|
||
| @cache | ||
| def get_dag_bag() -> DagBag: | ||
| """Create a DagBag by adding the files that are not supported to .airflowignore""" | ||
|
|
||
| with open(AIRFLOW_IGNORE_FILE, "w+") as file: | ||
| for dagfile in ALL_FILES_TO_IGNORE: | ||
| print(f"Adding {dagfile} to .airflowignore") | ||
| file.writelines([f"{dagfile}\n"]) | ||
|
|
||
| print(".airflowignore contents: ") | ||
| print(AIRFLOW_IGNORE_FILE.read_text()) | ||
| db = DagBag(EXAMPLE_DAGS_DIR, include_examples=False) | ||
| assert db.dags | ||
| assert not db.import_errors | ||
| return db | ||
|
|
||
|
|
||
| def get_dag_ids() -> list[str]: | ||
| dag_bag = get_dag_bag() | ||
| return dag_bag.dag_ids | ||
|
|
||
|
|
||
| @pytest.mark.integration | ||
| @pytest.mark.parametrize("dag_id", get_dag_ids()) | ||
| def test_example_dag(session, dag_id: str): | ||
| dag_bag = get_dag_bag() | ||
| dag = dag_bag.get_dag(dag_id) | ||
| dag.test() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.