Skip to content

Commit

Permalink
Merge pull request #8 from dobrovolsky/patch-1
Browse files Browse the repository at this point in the history
Fix percent condition evaluation
  • Loading branch information
n4mespace authored Mar 13, 2024
2 parents e25d010 + f4ba7d8 commit 1d414a0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions featureflags_client/http/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def except_false(func: Callable) -> Callable:
def wrapper(ctx: Dict[str, Any]) -> Any:
try:
return func(ctx)
except TypeError:
except (TypeError, ValueError):
return False

return wrapper
Expand Down Expand Up @@ -79,7 +79,7 @@ def percent(name: str, value: Any) -> Callable:
@except_false
def proc(ctx: Dict[str, Any]) -> bool:
ctx_val = ctx.get(name, _UNDEFINED)
return ctx_val is not _UNDEFINED and hash(ctx_val) % 100 < value
return ctx_val is not _UNDEFINED and hash(ctx_val) % 100 < int(value)

return proc

Expand Down
3 changes: 3 additions & 0 deletions featureflags_client/tests/http/test_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ def test_percent():

assert check_op(_UNDEFINED, percent, 100) is False

assert check_op("foo", percent, '100') is True
assert check_op("foo", percent, 'not_number') is False


def test_regexp():
assert check_op("anything", regexp, ".") is True
Expand Down

0 comments on commit 1d414a0

Please sign in to comment.