Nataneljpwd commented on code in PR #59928:
URL: https://github.com/apache/airflow/pull/59928#discussion_r2658949082


##########
airflow-core/src/airflow/dag_processing/dagbag.py:
##########
@@ -439,7 +439,20 @@ def parse(mod_name, filepath):
                 spec = importlib.util.spec_from_loader(mod_name, loader)
                 new_module = importlib.util.module_from_spec(spec)
                 sys.modules[spec.name] = new_module
-                loader.exec_module(new_module)
+                module_dir = os.fspath(Path(filepath).parent)

Review Comment:
   It looks like a patch only of it is 1 directory above or below, what happens 
when a task is nested 2 modules deep?



##########
airflow-core/src/airflow/dag_processing/dagbag.py:
##########
@@ -439,7 +439,20 @@ def parse(mod_name, filepath):
                 spec = importlib.util.spec_from_loader(mod_name, loader)
                 new_module = importlib.util.module_from_spec(spec)
                 sys.modules[spec.name] = new_module
-                loader.exec_module(new_module)
+                module_dir = os.fspath(Path(filepath).parent)
+                # Insert module directory into sys.path to allow relative 
imports. Imp to note
+                # that this is just for the duration of 
`loader.exec_module(new_module)`, ensuring
+                # that helper modules located alongside the DAG are importable.
+                path_inserted = False

Review Comment:
   Do we need this intermediate variable? As it will be in position 0 only when 
we add it there



##########
airflow-core/src/airflow/dag_processing/dagbag.py:
##########
@@ -439,7 +439,20 @@ def parse(mod_name, filepath):
                 spec = importlib.util.spec_from_loader(mod_name, loader)

Review Comment:
   Maybe we should change to not use a source file loader and instead use 
spec_from_file_location and use the loader withing the spec?
   I think it can solve this issue



-- 
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]

Reply via email to