Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clean_value in FlagStateForm #59

Closed
Weltraum opened this issue Apr 3, 2020 · 0 comments · Fixed by #61
Closed

Add clean_value in FlagStateForm #59

Weltraum opened this issue Apr 3, 2020 · 0 comments · Fixed by #61

Comments

@Weltraum
Copy link

Weltraum commented Apr 3, 2020

An sad mistake in the name broke the application, I wrote Flase instead of False:

  File "/Users/vlad/.pyenv/versions/worldskils50+/lib/python3.6/site-packages/flags/state.py", line 46, in flag_enabled
    return flag_state(flag_name, **kwargs)
  File "/Users/vlad/.pyenv/versions/worldskils50+/lib/python3.6/site-packages/flags/state.py", line 41, in flag_state
    return _flag_state(flag_name, **kwargs)
  File "/Users/vlad/.pyenv/versions/worldskils50+/lib/python3.6/site-packages/flags/state.py", line 28, in _flag_state
    return flag.check_state(**kwargs)
  File "/Users/vlad/.pyenv/versions/worldskils50+/lib/python3.6/site-packages/flags/sources.py", line 56, in check_state
    (c, c.check(**kwargs)) for c in self.conditions
  File "/Users/vlad/.pyenv/versions/worldskils50+/lib/python3.6/site-packages/flags/sources.py", line 56, in <listcomp>
    (c, c.check(**kwargs)) for c in self.conditions
  File "/Users/vlad/.pyenv/versions/worldskils50+/lib/python3.6/site-packages/flags/sources.py", line 28, in check
    return self.fn(self.value, **kwargs)
  File "/Users/vlad/.pyenv/versions/worldskils50+/lib/python3.6/site-packages/flags/conditions.py", line 62, in boolean_condition
    return strtobool(condition.strip().lower())
  File "/Users/vlad/.pyenv/versions/3.6.10/lib/python3.6/distutils/util.py", line 317, in strtobool
    raise ValueError("invalid truth value %r" % (val,))
ValueError: invalid truth value 'flase'

This happened because I placed the check flag_enabled('MY_FLAG') in middleware.

I have now redefined the class FlagStateForm:

class CleanFlagStateForm(FlagStateForm):

    def clean_value(self):
        condition = self.cleaned_data.get('condition')
        value = self.cleaned_data.get('value')
        try:
            CONDITIONS[condition](value)
        except Exception as e:
            raise forms.ValidationError(e)
        return value

But it seems to me that this check should be in the library itself

willbarton added a commit that referenced this issue Apr 17, 2020
Closes #59. Flag state values were not previously validated in the `FlagStateForm`, resulting in potential exceptions being raised on flag state checks.

Implementation based on suggestion by @Weltraum.
willbarton added a commit that referenced this issue May 21, 2020
Closes #59. Flag state values were not previously validated in the `FlagStateForm`, resulting in potential exceptions being raised on flag state checks.

Implementation based on suggestion by @Weltraum.
willbarton added a commit that referenced this issue Jun 10, 2020
Closes #59. Flag state values were not previously validated in the `FlagStateForm`, resulting in potential exceptions being raised on flag state checks.

Implementation based on suggestion by @Weltraum.
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 a pull request may close this issue.

1 participant