This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 445549aad5e Fix wtforms-mocking condition (#70811)
445549aad5e is described below

commit 445549aad5e26840ba33ed37dfab3690f5b35216
Author: Tzu-ping Chung <[email protected]>
AuthorDate: Fri Jul 31 18:29:59 2026 +0800

    Fix wtforms-mocking condition (#70811)
    
    The previous code
    
        "wtforms.StringField" not in sys.modules
    
    always evaluates to True because StringField is not a module, and is
    never present in sys.modules even if wtforms IS installed and imported.
    
    Judging from surrounding code, I think the original intention is to only
    patch if wtforms is not installed (and thuse a MagicMock was injected in
    the previous block). This changes the check to reflect my assumed
    intention.
    
    I also tightened the custom ModuleNotFoundError a bit to carry more
    useful information.
---
 .../src/airflow/api_fastapi/core_api/services/ui/connections.py       | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git 
a/airflow-core/src/airflow/api_fastapi/core_api/services/ui/connections.py 
b/airflow-core/src/airflow/api_fastapi/core_api/services/ui/connections.py
index 75a13a175e4..73519c52717 100644
--- a/airflow-core/src/airflow/api_fastapi/core_api/services/ui/connections.py
+++ b/airflow-core/src/airflow/api_fastapi/core_api/services/ui/connections.py
@@ -153,14 +153,14 @@ class HookMetaService:
         ]:
             try:
                 if not find_spec(mod_name):
-                    raise ModuleNotFoundError
+                    raise ModuleNotFoundError(f"No module named {mod_name!r}", 
name=mod_name)
             except ModuleNotFoundError:
                 sys.modules[mod_name] = MagicMock()
 
         # We conditionally inject mock classes for missing dependencies
         # to ensure `ProvidersManager` can initialize hook connection widgets
         # without crashing when FAB/WTForms are not installed.
-        if "wtforms.StringField" not in sys.modules:
+        if isinstance(sys.modules.get("wtforms"), MagicMock):
             # Only apply mocks if the actual module wasn't loaded beforehand.
             # This avoids thread-safety issues caused by `unittest.mock.patch` 
mutating global states.
             with (

Reply via email to