Skip to content

fix(api): decide module conditions by result truthiness, not exception-presence - #398

Open
chinmayajha wants to merge 1 commit into
mozarkai:mainfrom
chinmayajha:fix/flow-control-module-condition
Open

chinmayajha wants to merge 1 commit into
mozarkai:mainfrom
chinmayajha:fix/flow-control-module-condition

Conversation

@chinmayajha

Copy link
Copy Markdown
Collaborator

Fixes #385.

FlowControl._handle_module_condition treated a module-name condition as true whenever the module ran without raising — ignoring bool(result). A module returning an empty/falsy result therefore wrongly ran its target (and skipped else), contradicting the docstring and the sibling expression path _is_condition_true.

This decides truth by bool(result) for both the plain and inverted (!) forms, and flips the two xfail(strict) tests added in the test overhaul to passing (test_falsy_module_skips_target_runs_else, test_falsy_module_no_else_returns_none).

⚠️ Behaviour change to a shipped keyword: a suite relying on "an empty module condition still runs the target" will change. Full suite green (567 passed).

@malto101

Copy link
Copy Markdown
Member

This is quite a breaking change
Will need some to test this and then come back to this

@chinmayajha chinmayajha self-assigned this Jul 24, 2026
@chinmayajha
chinmayajha force-pushed the fix/flow-control-module-condition branch from 5e347c7 to 5fb7317 Compare July 24, 2026 10:15
@sonarqubecloud

Copy link
Copy Markdown

@malto101

Copy link
Copy Markdown
Member

before moving forward with this,
@chinmayajha could you verify if all existing running tests present in mozark is compatible with this change
mainly the tests which uses conditions

…sence

Closes mozarkai#385.

FlowControl._handle_module_condition decided whether a module-name condition was
true by whether execute_module() *raised*, not by the truthiness of its result.
A module that ran successfully but returned an empty/falsy result (e.g. []) was
treated as true and its target executed anyway — contradicting both the
_evaluate_conditions docstring ("returns the result of executing the module if
non-empty") and the sibling expression path _is_condition_true, which already
uses bool(result).

Compute the condition as `bool(result)` (a raising module is false, as in
_is_condition_true), apply the optional `!` inversion, and only run the target
when the condition is true — otherwise return None so the caller falls through to
the else branch. This also collapses the duplicated target-execution/E0401
wrapping into a single path.

The two tests that pinned the intended behaviour as xfail(strict) in
test_flow_control_all.py (test_falsy_module_skips_target_runs_else,
test_falsy_module_no_else_returns_none) now pass; their markers are removed.

Behaviour change: a suite that relied on "an empty-result module condition still
runs its target" will now take the else branch instead.
@chinmayajha
chinmayajha force-pushed the fix/flow-control-module-condition branch from 5fb7317 to e0cc009 Compare October 22, 2026 11:39
@sonarqubecloud

Copy link
Copy Markdown

thakur-patel
thakur-patel previously approved these changes Nov 25, 2026

@thakur-patel thakur-patel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Product review: approved. I've reviewed the intent and use case of this change, and it makes sense from a user and product point of view. This covers product intent and use case only. I haven't reviewed the implementation, so please rely on the code reviewers for that.

@thakur-patel
thakur-patel dismissed their stale review November 25, 2026 10:18

Approval withdrawn: posted by mistake. This PR is outside the product review scope.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FlowControl module condition decides truth by exception-presence, not result truthiness

3 participants