Skip to content

fix:boolean parameter without defaullt value defaults to False#352

Open
DimitriKwihangana wants to merge 4 commits intomainfrom
HEXA-1480-pipeline-launcher-widget-fix-boolean-parameter-without-default-value
Open

fix:boolean parameter without defaullt value defaults to False#352
DimitriKwihangana wants to merge 4 commits intomainfrom
HEXA-1480-pipeline-launcher-widget-fix-boolean-parameter-without-default-value

Conversation

@DimitriKwihangana
Copy link
Contributor

Fix the behavior of boolean parameters in the pipeline launcher widget. When a boolean parameter is defined without a default value, userswere getting a validation error ("parameter is required") instead of the parameter defaulting to False.

Changes

  • Modified _validate_single() in openhexa/sdk/pipelines/parameter.py
  • Added special handling for boolean parameters: when no default is provided, they now default to False instead of raising a validation
    error

How to test

  • Create a pipeline with a boolean parameter that has no default value (e.g., @parameter("verbose", type=bool, required=True)).
  • Run the pipeline without passing the flag. Previously this would raise a ParameterValueError: verbose is required error. After the fix, the pipeline should run successfully with the parameter defaulting to False.

Comment on lines 527 to 528
elif normalized_value is None and isinstance(self.type, Boolean) and self.required:
normalized_value = False # Required booleans default to False when no default is set
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't this be moved to

        if normalized_value is None:
            if self.required:
                raise ParameterValueError(f"{self.code} is required")

To avoid duplication of condition check ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, also: we can always default booleans that are None to False, regardless of if they're required

normalized_value = self.default
elif normalized_value is None and isinstance(self.type, Boolean) and self.required:
normalized_value = False # Required booleans default to False when no default is set

Copy link
Contributor

Choose a reason for hiding this comment

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

I propose to add a unit test to cover this edge case

Copy link
Contributor

Choose a reason for hiding this comment

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

(This ensures that we avoid regressions in the future but also it greatly simplifies code reviews, if the test coverage is good and the intent of tests are good we might not need to pull up the code and test)

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed

Copy link
Contributor

@bramj bramj left a comment

Choose a reason for hiding this comment

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

Great! Works perfectly 👍

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.

3 participants