Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[processing] correctly parse default value for boolean parameters upo…
…n construction
- Loading branch information
946f4e4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@volaya @medspx does the unit test need to be updated to reflect this change or has it introduced a regression? The processing tests are failing since this commit.
946f4e4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most likely the tests should be adapted. @m-kuhn?
946f4e4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems that
None
is no longer accepted as value for boolean parameters, so there is no way to specify an optional parameter.What's fixed with this commit? Would it make sense to make
parseBool
aware ofNone
?The failing code is
@michaelkirk
946f4e4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Failure is pretty clear:
https://github.com/qgis/QGIS/blob/master/python/plugins/processing/tests/ParametersTest.py#L64
From just looking at the code, I would expect a newly initialized optional BooleanParameter to have a value of
None
notFalse
. It seems like the test should stay and the application should change.946f4e4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michaelkirk it seems to me that this test actually produces an non-optional parameter (see my last comment for the defaults)
BUT the defaults are actually conflicting
default=None, optional=False
AND even if it was optional, None would not be accepted, so the code seems actually to show room for improvement.946f4e4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@m-kuhn you're right. Parameters are
required
by default.I think that we should maintain a distinction between None and False. So the brain dead way would be something like:
@volaya can you give some insight into why you made this change? What is using the ParameterBoolean class that passes (non boolean) defaults that must first be parsed?
edit: code
946f4e4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be straightforward to adjust the first line of parseBool to
946f4e4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somehow I was conflating
parseBool
withbool
e.g.bool(None)
. Given that we've got our own specific thing->Bool method, we might as well make it do what we want.Pending @volaya's original motivations for this change, I'd say @m-kuhn's suggestion to alter parseBool is good 👍
946f4e4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michaelkirk I changed it because of this
8798c42
Basically, as it was before, it was not correctly working for algorithms that are described in a text file (SAGA, GRASS), since the value passed was a text string with "True" or "False" and that was always understood as a true due to the non empty string. Passing that string through the parseBool method fixed that.
946f4e4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@volaya Can you point me to the text file parsing code?
946f4e4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michaelkirk https://github.com/qgis/QGIS/blob/master/python/plugins/processing/core/parameters.py#L47
That method is the one that Jurgen fixed to solve the issue with the test