DonHaul opened a new issue, #59003:
URL: https://github.com/apache/airflow/issues/59003
### Apache Airflow version
Other Airflow 2/3 version (please specify below)
### If "Other Airflow 2/3 version" selected, which one?
3.0.6
### What happened?
I have a dag that is importing a task from a another folder also in the
`dags` folder.
This dag parses well and I can trigger it / run it normally in the airflow
UI.
But in the cli when running commands such as `airflow dags reserialize` or
in this case `airflow tasks clear my_dag`, I get the error shown below.
This is because some of the modules can't be imported when in the CLI
`environment`
```bash
airflow@f24b2477fda6:/opt/airflow$ airflow tasks clear my_dag
[2025-12-03T14:59:26.505+0000] {dagbag.py:585} INFO - Filling up the DagBag
from /opt/airflow/dags/my_dag.py
[2025-12-03T14:59:26.517+0000] {dagbag.py:404} ERROR - Failed to import:
/opt/airflow/dags/my_dag.py
Traceback (most recent call last):
File
"/home/airflow/.local/lib/python3.11/site-packages/airflow/models/dagbag.py",
line 394, in parse
loader.exec_module(new_module)
File "<frozen importlib._bootstrap_external>", line 940, in exec_module
File "<frozen importlib._bootstrap>", line 241, in
_call_with_frames_removed
File "/opt/airflow/dags/my_dag.py", line 2, in <module>
from module.task_b import task_b
ModuleNotFoundError: No module named 'module'
Traceback (most recent call last):
File "/home/airflow/.local/bin/airflow", line 7, in <module>
sys.exit(main())
^^^^^^
File
"/home/airflow/.local/lib/python3.11/site-packages/airflow/__main__.py", line
55, in main
args.func(args)
File
"/home/airflow/.local/lib/python3.11/site-packages/airflow/cli/cli_config.py",
line 48, in command
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File
"/home/airflow/.local/lib/python3.11/site-packages/airflow/utils/cli.py", line
112, in wrapper
return f(*args, **kwargs)
^^^^^^^^^^^^^^^^^^
File
"/home/airflow/.local/lib/python3.11/site-packages/airflow/utils/providers_configuration_loader.py",
line 55, in wrapped_function
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File
"/home/airflow/.local/lib/python3.11/site-packages/airflow/cli/commands/task_command.py",
line 429, in task_clear
dags = [get_dag_by_file_location(args.dag_id)]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File
"/home/airflow/.local/lib/python3.11/site-packages/airflow/utils/cli.py", line
238, in get_dag_by_file_location
return dagbag.dags[dag_id]
~~~~~~~~~~~^^^^^^^^
KeyError: 'my_dag'
```
### What you think should happen instead?
When running CLIs commands, the imports should behave the same was as in the
ui.
As such, commands like `airflow dags reserialize` or `airflow tasks clear
DAG_ID` should run as well
### How to reproduce
dags folder structure
```
/dags
my_dag.py
/module
task_b.py
```
my_dag.py
```
from airflow.sdk import dag, task
from module.task_b import task_b
@dag
def my_dag():
@task
def task_a(**context):
print("This is Task A")
task_a() >> task_b()
my_dag()
```
task_b.py
```
from airflow.sdk import task
@task
def task_b(**context):
print("This is Task B")
```
Run command `airflow tasks clear my_dag`
### Operating System
Debian GNU/Linux 12 (bookworm)
### Versions of Apache Airflow Providers
_No response_
### Deployment
Docker-Compose
### Deployment details
_No response_
### Anything else?
_No response_
### Are you willing to submit PR?
- [ ] Yes I am willing to submit a PR!
### Code of Conduct
- [x] I agree to follow this project's [Code of
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
--
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]