-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Fix DAG bundle imports in subprocess operators #57631
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 DAG bundle imports in subprocess operators #57631
Conversation
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
|
931175e to
b582f37
Compare
213c76c to
ea401c8
Compare
3d1ae9f to
65d47a1
Compare
potiuk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks great. I would love however that someone else from the bundle-work-related commiters take a look.
@ephraimbuddy @jedcunningham ? Maybe one of you :) ?
providers/standard/tests/unit/standard/operators/test_python.py
Outdated
Show resolved
Hide resolved
providers/standard/tests/unit/standard/operators/test_python.py
Outdated
Show resolved
Hide resolved
e350ea6 to
0c56586
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should I mark the reviews as resolved myself or the reviewer or other maintained will do that?
Thanks for the update! Please feel free to resolve the addressed comments.
6281cbd to
35200dd
Compare
35200dd to
b4d9078
Compare
Lee-W
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Just rebased. let's see whether there's any other failure
9472f43 to
ee0a5eb
Compare
|
By rebasing I have overwritten the previous workflow Lee-W was waiting for. Here is the run link: https://github.com/apache/airflow/actions/runs/19510952139?pr=57631 On the latest rebase the same issue of "Socket operation on non socket" persists on my local tests, so I don't think it is relevant to run the CI again for now, given the time it takes |
ee0a5eb to
f7536af
Compare
|
Changed the test to mock subprocess execution and just test if the bundle path is in the |
Add the bundle path to PYTHONPATH in operators on the standard provider that runs in a subprocess to fix import errors in Airflow 3.x.
The _callable_that_imports_from_bundle function was catching broad Exception which could mask unexpected errors. Changed to catch ImportError specifically since that's what we're testing for.
Move DAG bundle import tests from mixin pattern to a dedicated parameterized test class to improve test isolation. The new TestDagBundleImportInSubprocess class tests subprocess-based Python operators using pytest parametrization.
… of plain string on the first argument
- Fix Dag nomenclature usage - Simplify bundle path obtention logic - Add bunde path after user-defined paths - Use tmp_path pytest fixture instead of a manual one
- Return `None` if `bundle_instance` is not present to avoid attribute errors. - Ensure the bundle path is only added to `PYTHONPATH` when defined
- Mock subprocess execution to avoid environment-related issues. - Test if the bundle path was passed to the subprocess in the env argument instead
d3692ab to
f6e8d68
Compare
jscheffl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good in my view.
* Fix DAG bundle imports in subprocess operators (apache#56783) Add the bundle path to PYTHONPATH in operators on the standard provider that runs in a subprocess to fix import errors in Airflow 3.x. * Apply precommit formatting changes * Change broad exception to specific ImportError in DAG bundle test helper The _callable_that_imports_from_bundle function was catching broad Exception which could mask unexpected errors. Changed to catch ImportError specifically since that's what we're testing for. * Refactor DAG bundle import tests into separate parameterized test class Move DAG bundle import tests from mixin pattern to a dedicated parameterized test class to improve test isolation. The new TestDagBundleImportInSubprocess class tests subprocess-based Python operators using pytest parametrization. * Fix CI ruff static check, parametrize attribute expects tuple instead of plain string on the first argument * Apply review suggestions - Fix Dag nomenclature usage - Simplify bundle path obtention logic - Add bunde path after user-defined paths - Use tmp_path pytest fixture instead of a manual one * Fix bundle path handling in subprocess operators - Return `None` if `bundle_instance` is not present to avoid attribute errors. - Ensure the bundle path is only added to `PYTHONPATH` when defined * Refactor DAG bundle import test - Mock subprocess execution to avoid environment-related issues. - Test if the bundle path was passed to the subprocess in the env argument instead * Remove unused pytest marks.
* Fix DAG bundle imports in subprocess operators (apache#56783) Add the bundle path to PYTHONPATH in operators on the standard provider that runs in a subprocess to fix import errors in Airflow 3.x. * Apply precommit formatting changes * Change broad exception to specific ImportError in DAG bundle test helper The _callable_that_imports_from_bundle function was catching broad Exception which could mask unexpected errors. Changed to catch ImportError specifically since that's what we're testing for. * Refactor DAG bundle import tests into separate parameterized test class Move DAG bundle import tests from mixin pattern to a dedicated parameterized test class to improve test isolation. The new TestDagBundleImportInSubprocess class tests subprocess-based Python operators using pytest parametrization. * Fix CI ruff static check, parametrize attribute expects tuple instead of plain string on the first argument * Apply review suggestions - Fix Dag nomenclature usage - Simplify bundle path obtention logic - Add bunde path after user-defined paths - Use tmp_path pytest fixture instead of a manual one * Fix bundle path handling in subprocess operators - Return `None` if `bundle_instance` is not present to avoid attribute errors. - Ensure the bundle path is only added to `PYTHONPATH` when defined * Refactor DAG bundle import test - Mock subprocess execution to avoid environment-related issues. - Test if the bundle path was passed to the subprocess in the env argument instead * Remove unused pytest marks.
closes: #56783
Resolve
ModuleNotFoundErrorfor DAG bundle imports within standard operator subprocesses in Airflow 3.x.Problem
Subprocesses spawned by these operators don't have the DAG bundle path in
PYTHONPATH(see #53617), causing imports to fail when modules from the bundle are imported inside the callable function.Solution
Extracts bundle path from task instance context during execution call
Add extracted bundle path to subprocess
PYTHONPATHenvironment variableGuard with
AIRFLOW_V_3_0_PLUScheck for backward compatibility