-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[airlift] Fix DagsterOperator task->asset lookup (#23985)
## Summary The Dagster Operator was still using the op name to figure out what assets to materialize. It was returning an empty list. Now, we perform that lookup using the asset tags. Extra motivation to get https://linear.app/dagster-labs/issue/PLUS-1325/centralize-targeting-logic-on-asset-tags-instead-of-op-tags-naming in so we have a standard way of mapping back and forth. Follow up from me is more aggressive errors if we dont' find any matching assets. ## Test Plan Added integration test which parallels the existing switcheroo test (that relies on the naming convention) but uses the `dag_defs`, `task_defs` methods instead of naming convention. ## Changelog [New] `NOCHANGELOG`
- Loading branch information
Showing
7 changed files
with
114 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -5,6 +5,10 @@ | |
assetKey { | ||
path | ||
} | ||
tags { | ||
key | ||
value | ||
} | ||
opName | ||
jobs { | ||
id | ||
|
File renamed without changes.
File renamed without changes.
68 changes: 68 additions & 0 deletions
68
...dagster_airlift_tests/integration_tests/airflow_op_switcheroo_tags/dags/switcheroo_dag.py
This file contains 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,68 @@ | ||
import logging | ||
import os | ||
from datetime import datetime | ||
|
||
from airflow import DAG | ||
from airflow.operators.python import PythonOperator | ||
from dagster_airlift.in_airflow import mark_as_dagster_migrating | ||
from dagster_airlift.migration_state import ( | ||
AirflowMigrationState, | ||
DagMigrationState, | ||
TaskMigrationState, | ||
) | ||
|
||
logging.basicConfig() | ||
logging.getLogger().setLevel(logging.INFO) | ||
requests_log = logging.getLogger("requests.packages.urllib3") | ||
requests_log.setLevel(logging.INFO) | ||
requests_log.propagate = True | ||
|
||
|
||
def write_to_file_in_airflow_home() -> None: | ||
airflow_home = os.environ["AIRFLOW_HOME"] | ||
with open(os.path.join(airflow_home, "airflow_home_file.txt"), "w") as f: | ||
f.write("Hello") | ||
|
||
|
||
def write_to_other_file_in_airflow_home() -> None: | ||
airflow_home = os.environ["AIRFLOW_HOME"] | ||
with open(os.path.join(airflow_home, "other_airflow_home_file.txt"), "w") as f: | ||
f.write("Hello") | ||
|
||
|
||
default_args = { | ||
"owner": "airflow", | ||
"depends_on_past": False, | ||
"start_date": datetime(2023, 1, 1), | ||
"retries": 1, | ||
} | ||
|
||
dag = DAG( | ||
"the_dag", default_args=default_args, schedule_interval=None, is_paused_upon_creation=False | ||
) | ||
op_to_migrate = PythonOperator( | ||
task_id="some_task", python_callable=write_to_file_in_airflow_home, dag=dag | ||
) | ||
op_doesnt_migrate = PythonOperator( | ||
task_id="other_task", python_callable=write_to_other_file_in_airflow_home, dag=dag | ||
) | ||
# Add a dependency between the two tasks | ||
op_doesnt_migrate.set_upstream(op_to_migrate) | ||
|
||
# # set up the debugger | ||
# print("Waiting for debugger to attach...") | ||
# debugpy.listen(("localhost", 7778)) | ||
# debugpy.wait_for_client() | ||
mark_as_dagster_migrating( | ||
global_vars=globals(), | ||
migration_state=AirflowMigrationState( | ||
dags={ | ||
"the_dag": DagMigrationState( | ||
tasks={ | ||
"some_task": TaskMigrationState(task_id="some_task", migrated=True), | ||
"other_task": TaskMigrationState(task_id="other_task", migrated=True), | ||
} | ||
) | ||
} | ||
), | ||
) |
13 changes: 13 additions & 0 deletions
13
...irlift/dagster_airlift_tests/integration_tests/airflow_op_switcheroo_tags/dagster_defs.py
This file contains 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,13 @@ | ||
from dagster import Definitions, asset | ||
from dagster_airlift.core import dag_defs, task_defs | ||
|
||
|
||
@asset | ||
def my_asset_for_some_task(): | ||
return "asset_value" | ||
|
||
|
||
defs = dag_defs( | ||
"the_dag", | ||
task_defs("some_task", Definitions(assets=[my_asset_for_some_task])), | ||
) |
This file contains 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