@@ -141,6 +141,19 @@ Airflow, when running dynamically adds three directories to the ``sys.path``:
141141- The ``config `` folder: It is configured by setting ``AIRFLOW_HOME `` variable (``{AIRFLOW_HOME}/config ``) by default.
142142- The ``plugins `` Folder: It is configured with option ``plugins_folder `` in section ``[core] ``.
143143
144+ .. warning ::
145+
146+ Unlike the ``dags `` and ``config `` folders, which are simply appended to ``sys.path ``
147+ (making them available for explicit imports only), the ``plugins `` folder's ``.py `` files
148+ are **actively imported at Airflow startup ** and registered in ``sys.modules `` under the
149+ bare filename as a top-level module. The subdirectory structure is ignored when
150+ determining the module name, so a file at ``plugins/my_project/operators/hdfs.py `` is
151+ registered as ``sys.modules["hdfs"] ``, not ``sys.modules["my_project.operators.hdfs"] ``.
152+ Because ``sys.modules `` is populated at process startup, any ``import hdfs `` anywhere in
153+ the process — including inside installed providers or third-party libraries — will resolve
154+ to the plugin file instead of the intended package. See :ref: `plugins:loading ` for the
155+ full plugin loading lifecycle.
156+
144157.. note ::
145158 The Dags folder in Airflow 2 and 3 should not be shared with the webserver. While you can do it, unlike in Airflow 1.10,
146159 Airflow has no expectations that the Dags folder is present in the webserver. In fact it's a bit of
@@ -186,6 +199,19 @@ folders that will clash with other packages already present in the system. For e
186199create ``airflow/operators `` subfolder it will not be accessible because Airflow already has a package
187200named ``airflow.operators `` and it will look there when importing ``from airflow.operators ``.
188201
202+ .. warning ::
203+
204+ For the ``plugins `` folder, the name-collision risk extends to ``.py `` files at **any
205+ depth **, not just the top level. Because plugin files are automatically imported at
206+ startup and registered in ``sys.modules `` by bare filename alone, a file at
207+ ``plugins/my_company/operators/hdfs.py `` registers as ``sys.modules["hdfs"] ``, silently
208+ shadowing the PyPI ``hdfs `` package. This can break providers that depend on it — for
209+ example, ``apache-airflow-providers-apache-hdfs `` imports ``from hdfs import HdfsError ``,
210+ which fails with ``ImportError `` if a plugin file named ``hdfs.py `` exists anywhere in
211+ the plugins folder. Note that if the conflicting file is added while Airflow is already
212+ running, the collision will not occur until the next restart, making the root cause
213+ difficult to diagnose.
214+
189215Don't use relative imports
190216..........................
191217
0 commit comments