Skip to content

Commit e839b82

Browse files
committed
fix targeting test
Signed-off-by: Lea Konvalinka <lea.konvalinka@dynatrace.com>
1 parent 70b456d commit e839b82

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

‎providers/openfeature-provider-flagd/src/openfeature/contrib/provider/flagd/resolvers/process/custom_ops.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import mmh3
77
import semver
88

9+
MAX_WEIGHT_SUM = 2_147_483_647 # MaxInt32
10+
911
JsonPrimitive: typing.TypeAlias = str | bool | float | int
1012
JsonLogicArg: typing.TypeAlias = JsonPrimitive | Sequence[JsonPrimitive]
1113

@@ -18,7 +20,7 @@ class Fraction:
1820
weight: int = 1
1921

2022

21-
def _resolve_bucket_by(data: dict, args: tuple) -> tuple[typing.Optional[str], tuple]:
23+
def _resolve_bucket_by(data: dict, args: tuple) -> tuple[str | None, tuple]:
2224
"""Resolve the hash key and remaining fraction args from the fractional operator arguments."""
2325
if isinstance(args[0], str):
2426
return args[0], args[1:]
@@ -57,8 +59,8 @@ def fractional(data: dict, *args: JsonLogicArg) -> str | None:
5759
logger.debug(f"Invalid {args} configuration")
5860
return None
5961

60-
if total_weight > 2_147_483_647:
61-
logger.error("Total fractional weight exceeds MaxInt32 (2,147,483,647).")
62+
if total_weight > MAX_WEIGHT_SUM:
63+
logger.error(f"Total fractional weight exceeds MaxInt32 ({MAX_WEIGHT_SUM:,}).")
6264
return None
6365

6466
bucket = (hash_value * total_weight) >> 32

‎providers/openfeature-provider-flagd/tests/test_targeting.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def test_should_evaluate_valid_rule2(self):
182182
logic = targeting(
183183
"flagA", rule, EvaluationContext(attributes={"key": "bucketKeyB"})
184184
)
185-
assert logic == "blue"
185+
assert logic == "red"
186186

187187
def test_should_evaluate_valid_rule_with_targeting_key(self):
188188
rule = {
@@ -193,7 +193,7 @@ def test_should_evaluate_valid_rule_with_targeting_key(self):
193193
}
194194

195195
logic = targeting("flagA", rule, EvaluationContext(targeting_key="bucketKeyB"))
196-
assert logic == "blue"
196+
assert logic == "red"
197197

198198
def test_should_evaluate_valid_rule_with_targeting_key_although_one_does_not_have_a_fraction(
199199
self,
@@ -203,7 +203,7 @@ def test_should_evaluate_valid_rule_with_targeting_key_although_one_does_not_hav
203203
}
204204

205205
logic = targeting("flagA", rule, EvaluationContext(targeting_key="bucketKeyB"))
206-
assert logic == "blue"
206+
assert logic == "red"
207207

208208
def test_should_return_null_if_targeting_key_is_missing(self):
209209
rule = {

0 commit comments

Comments
 (0)