You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rule Conditions allow users to evaluate context attributes against values and actions defined in Rule Conditions.
The condition can easily be pivoted on a certain value in the context evaluating to falsy values. Consider the following example -
The values attribute in conditions cannot accept any of the falsy values, some of which are essential to framing conditions in practical use-cases.
If any of the falsy values are present in the condition - the utility throws the error below
File~/venv/lib/python3.8/site-packages/aws_lambda_powertools/utilities/feature_flags/schema.py:330, inConditionsValidator.validate_condition_value(condition, rule_name)
328value=condition.get(CONDITION_VALUE, "")
329ifnotvalue:
-->330raiseSchemaValidationError(f"'value' key must not be empty, rule={rule_name}")
331action=condition.get(CONDITION_ACTION, "")
333# time actions need to be parsed to make sure date and time format is valid and timezone is recognizedSchemaValidationError: 'value'keymustnotbeempty, rule=unpaid_users
Falsy Values in context value
The conditions simply return evaluate to false if the value for the key passed in context is falsy. These are also extremely essential to framing conditions in practical use-cases.
Example -
🚨 The condition below will evaluate to False even if the context value (0) is NOT EQUAL to condition value (1) 🚨
ajwad-shaikh
changed the title
Bug: Feature Flag Rule Conditions cannot have Falsy values
Bug: Feature Flag Rule Conditions Values and Context Key Variables cannot have Falsy values
Mar 25, 2023
@ajwad-shaikh thanks for finding this. @heitorlessa I took the liberty of opening a PR with a fix and two tests.
I dont think the change in the feature_flags.py is required, as it has already passed schema validation, so i deleted this line entirely.
I must say I'm impressed with the quality of this bug report @ajwad-shaikh - THANK YOU for the lengths in which you took to describe not only the problem concisely, but also potential solutions to it regardless of the complexity.
We'll revert quickly with a patch release once we're confident with the fix!
Expected Behaviour
Rule Conditions allow users to evaluate context attributes against values and actions defined in Rule Conditions.
The condition can easily be pivoted on a certain value in the context evaluating to falsy values. Consider the following example -
Context-
Feature Flag -
The
values
attribute should be able to accept any value exceptnull
The condition should also honor any value for context key variable.
Current Behaviour
Definition - Falsy Values
In python, the following values evaluate to False in boolean context - these are known as falsy values.
Falsy Values in Condition
value
The
values
attribute in conditions cannot accept any of the falsy values, some of which are essential to framing conditions in practical use-cases.If any of the falsy values are present in the condition - the utility throws the error below
Falsy Values in context
value
The conditions simply return evaluate to false if the value for the key passed in context is falsy. These are also extremely essential to framing conditions in practical use-cases.
Example -
Code snippet
Falsy Values in Condition
value
Falsy Values in Context key
value
Possible Solution
Falsy Values in condition
value
Instead of
https://github.com/awslabs/aws-lambda-powertools-python/blob/f2435070d53aba8fced2901380438cc6015c6f49/aws_lambda_powertools/utilities/feature_flags/schema.py#L328-L330
suggest
Falsy Values in context key
value
Instead of
https://github.com/awslabs/aws-lambda-powertools-python/blob/f2435070d53aba8fced2901380438cc6015c6f49/aws_lambda_powertools/utilities/feature_flags/feature_flags.py#L49-L51
suggest
Steps to Reproduce
Shared code snippet should reproduce the issue
AWS Lambda Powertools for Python version
latest
AWS Lambda function runtime
3.6
Packaging format used
PyPi
Debugging logs
No response
The text was updated successfully, but these errors were encountered: