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

vatsrahul1001 pushed a commit to branch v3-3-test
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/v3-3-test by this push:
     new f0d61faf801 [v3-3-test] Fix wtforms-mocking condition (#70811) (#70821)
f0d61faf801 is described below

commit f0d61faf801cb0b8aeca1b918cc01a763fd41275
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Mon Aug 3 11:02:44 2026 +0530

    [v3-3-test] Fix wtforms-mocking condition (#70811) (#70821)
    
    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.
    (cherry picked from commit 445549aad5e26840ba33ed37dfab3690f5b35216)
    
    Co-authored-by: Tzu-ping Chung <[email protected]>
---
 .../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