Skip to content

Fix wtforms-mocking condition - #70811

Merged
potiuk merged 1 commit into
apache:mainfrom
astronomer:tighten-mock-wtforms
Jul 31, 2026
Merged

Fix wtforms-mocking condition#70811
potiuk merged 1 commit into
apache:mainfrom
astronomer:tighten-mock-wtforms

Conversation

@uranusjr

Copy link
Copy Markdown
Member

The previous code (introduced in #63986)

"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.

cc @Subham-KRLX

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.
@uranusjr
uranusjr requested a review from eladkal July 31, 2026 07:01
@uranusjr uranusjr added the backport-to-v3-3-test Backport to v3-3-test label Jul 31, 2026
@boring-cyborg boring-cyborg Bot added the area:API Airflow's REST/HTTP API label Jul 31, 2026
@uranusjr
uranusjr requested review from potiuk and vincbeck July 31, 2026 07:01
@potiuk potiuk added this to the Airflow 3.3.1 milestone Jul 31, 2026
@potiuk
potiuk merged commit 445549a into apache:main Jul 31, 2026
79 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Backport successfully created: v3-3-test

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
v3-3-test PR Link

github-actions Bot pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request Jul 31, 2026
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 445549a)

Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
aws-airflow-bot pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request Jul 31, 2026
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 445549a)

Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
vatsrahul1001 pushed a commit that referenced this pull request Aug 3, 2026
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 445549a)

Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API backport-to-v3-3-test Backport to v3-3-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants