jedcunningham commented on code in PR #51318:
URL: https://github.com/apache/airflow/pull/51318#discussion_r2122147893
##########
task-sdk/tests/task_sdk/execution_time/test_task_runner.py:
##########
@@ -275,6 +276,54 @@ def test_parse_not_found(test_dags_dir: Path,
make_ti_context, dag_id, task_id,
log.error.assert_has_calls([expected_error])
+def test_parse_module_in_bundle_root(tmp_path: Path, make_ti_context):
+ """Check that the bundle path is added to sys.path, so Dags can import
shared modules."""
+ tmp_path.joinpath("util.py").write_text("NAME = 'dag_name'")
+
+ dag1_path = tmp_path.joinpath("path_test.py")
+ dag1_code = """
+ from util import NAME
+ from airflow.sdk import DAG
+ from airflow.sdk.bases.operator import BaseOperator
+ with DAG(NAME):
+ BaseOperator(task_id="a")
+ """
+ dag1_path.write_text(textwrap.dedent(dag1_code))
+
+ what = StartupDetails(
+ ti=TaskInstance(
+ id=uuid7(),
+ task_id="a",
+ dag_id="dag_name",
+ run_id="c",
+ try_number=1,
+ ),
+ dag_rel_path="path_test.py",
+ bundle_info=BundleInfo(name="my-bundle", version=None),
+ requests_fd=0,
+ ti_context=make_ti_context(),
+ start_date=timezone.utcnow(),
+ )
+
+ with patch.dict(
+ os.environ,
+ {
+ "AIRFLOW__DAG_PROCESSOR__DAG_BUNDLE_CONFIG_LIST": json.dumps(
+ [
+ {
+ "name": "my-bundle",
+ "classpath":
"airflow.dag_processing.bundles.local.LocalDagBundle",
+ "kwargs": {"path": str(tmp_path), "refresh_interval":
1},
+ }
+ ]
+ ),
+ },
+ ):
+ ti = parse(what, mock.Mock())
+
+ assert ti.task.dag.dag_id == "dag_name"
Review Comment:
Yep, and `dag_name` came from the file in util. There isn't an easy way to
test directly "bundle path is on sys.path", so this is a reasonable alternative.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]