Skip to content

Commit 8e2db32

Browse files
authored
fix: Account for inversion in NOT_IN operator where context_value is None (#235)
1 parent 6703bf8 commit 8e2db32

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

UnleashClient/constraints/Constraint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def apply(self, context: dict = None) -> bool:
181181
else:
182182
# This is a special case in the client spec - so it's getting it's own handler here
183183
if self.operator is ConstraintOperators.NOT_IN:
184-
return True
184+
constraint_check = True
185185

186186
except Exception as excep: # pylint: disable=broad-except
187187
LOGGER.info("Could not evaluate context %s! Error: %s", self.context_name, excep)

tests/unit_tests/test_constraints.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ def constraint_NOTIN():
1515
yield Constraint(mock_constraints.CONSTRAINT_DICT_NOTIN)
1616

1717

18-
1918
def test_constraint_IN_match(constraint_IN):
2019
constraint = constraint_IN
2120
context = {
@@ -39,6 +38,16 @@ def test_constraint_IN_missingcontext(constraint_IN):
3938
assert not constraint.apply({})
4039

4140

41+
def test_constraint_NOTIN_missingcontext(constraint_NOTIN):
42+
constraint = constraint_NOTIN
43+
assert constraint.apply({})
44+
45+
46+
def test_constraint_NOTIN_missingcontext_inversion():
47+
constraint = Constraint(mock_constraints.CONSTRAINT_DICT_NOTIN_INVERT)
48+
assert not constraint.apply({})
49+
50+
4251
def test_constraint_NOTIN_match(constraint_NOTIN):
4352
constraint = constraint_NOTIN
4453
context = {

tests/utilities/mocks/mock_constraints.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@
2020
}
2121

2222

23+
CONSTRAINT_DICT_NOTIN_INVERT = \
24+
{
25+
"contextName": "appName",
26+
"operator": "NOT_IN",
27+
"values": [
28+
"test",
29+
"test2"
30+
],
31+
"inverted": True
32+
}
33+
34+
2335
CONSTRAINT_DICT_STR_INVERT = \
2436
{
2537
"contextName": "customField",
@@ -29,6 +41,7 @@
2941
"inverted": True
3042
}
3143

44+
3245
CONSTRAINT_DICT_STR_CONTAINS_CI = \
3346
{
3447
"contextName": "customField",

0 commit comments

Comments
 (0)