Skip to content

Commit 6f2bf13

Browse files
committed
fix: Fix an issue with rollouts with a missing attribute.
1 parent 878607e commit 6f2bf13

File tree

2 files changed

+66
-3
lines changed

2 files changed

+66
-3
lines changed

src/ldclient_rollout.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ match_weighted_variations(Bucket, [#{weight := Weight}|Rest], Sum) ->
147147
FlagKey :: ldclient_flag:key(),
148148
Salt :: binary(),
149149
ContextValue :: binary() | null) -> float().
150-
bucket_context_value(null, _FlagKey, _Salt, null) -> 0.0;
150+
151+
bucket_context_value(_Seed, _FlagKey, _Salt, null) -> 0.0;
151152
%% when no seed is present hash with `key.salt.attribute`
152153
bucket_context_value(null, FlagKey, Salt, ContextValue) ->
153154
bucket_hash(<<FlagKey/binary, $., Salt/binary, $., ContextValue/binary>>);

test/ldclient_rollout_SUITE.erl

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
can_rollout_experiment/1,
1616
untracked_variation_for_experiment_rollout_is_not_in_experiment/1,
1717
missing_kind_is_not_in_experiment/1,
18-
experiment_rollouts_do_not_use_bucket_by/1
18+
experiment_rollouts_do_not_use_bucket_by/1,
19+
missing_bucket_bucket_by_does_not_error/1,
20+
bucket_by_null_attribute_does_not_error/1
1921
]).
2022

2123
%%====================================================================
@@ -28,7 +30,9 @@ all() ->
2830
can_rollout_experiment,
2931
untracked_variation_for_experiment_rollout_is_not_in_experiment,
3032
missing_kind_is_not_in_experiment,
31-
experiment_rollouts_do_not_use_bucket_by
33+
experiment_rollouts_do_not_use_bucket_by,
34+
missing_bucket_bucket_by_does_not_error,
35+
bucket_by_null_attribute_does_not_error
3236
].
3337

3438
init_per_suite(Config) ->
@@ -116,3 +120,61 @@ experiment_rollouts_do_not_use_bucket_by(_) ->
116120
}),
117121
#{key => <<"flagKey">>, salt => <<"flagSalt">>},
118122
ldclient_context:set(<<"decoy">>, <<"valueZZZ">>, ldclient_context:new(<<"org-key">>, <<"org">>))).
123+
124+
missing_bucket_bucket_by_does_not_error_with_seed(_) ->
125+
{0, false} = ldclient_rollout:rollout_context(
126+
ldclient_rollout:new(#{
127+
<<"kind">> => <<"rollout">>,
128+
<<"contextKind">> => <<"user">>,
129+
<<"bucketBy">> => <<"missing">>,
130+
<<"seed">> => 1234567890,
131+
<<"variations">> => [
132+
#{<<"variation">> => 0, <<"weight">> => 50000, <<"untracked">> => false},
133+
#{<<"variation">> => 1, <<"weight">> => 50000, <<"untracked">> => false}
134+
]
135+
}),
136+
#{key => <<"flagKey">>, salt => <<"flagSalt">>},
137+
ldclient_context:new(<<"user-key">>)).
138+
139+
bucket_by_null_attribute_does_not_error_with_seed(_) ->
140+
{0, false} = ldclient_rollout:rollout_context(
141+
ldclient_rollout:new(#{
142+
<<"kind">> => <<"rollout">>,
143+
<<"contextKind">> => <<"user">>,
144+
<<"bucketBy">> => <<"null">>,
145+
<<"seed">> => 1234567890,
146+
<<"variations">> => [
147+
#{<<"variation">> => 0, <<"weight">> => 50000, <<"untracked">> => false},
148+
#{<<"variation">> => 1, <<"weight">> => 50000, <<"untracked">> => false}
149+
]
150+
}),
151+
#{key => <<"flagKey">>, salt => <<"flagSalt">>},
152+
ldclient_context:set(<<"null">>, null, ldclient_context:new(<<"user-key">>))).
153+
154+
missing_bucket_bucket_by_does_not_error_without_seed(_) ->
155+
{0, false} = ldclient_rollout:rollout_context(
156+
ldclient_rollout:new(#{
157+
<<"kind">> => <<"rollout">>,
158+
<<"contextKind">> => <<"user">>,
159+
<<"bucketBy">> => <<"missing">>,
160+
<<"variations">> => [
161+
#{<<"variation">> => 0, <<"weight">> => 50000, <<"untracked">> => false},
162+
#{<<"variation">> => 1, <<"weight">> => 50000, <<"untracked">> => false}
163+
]
164+
}),
165+
#{key => <<"flagKey">>, salt => <<"flagSalt">>},
166+
ldclient_context:new(<<"user-key">>)).
167+
168+
bucket_by_null_attribute_does_not_error_without_seed(_) ->
169+
{0, false} = ldclient_rollout:rollout_context(
170+
ldclient_rollout:new(#{
171+
<<"kind">> => <<"rollout">>,
172+
<<"contextKind">> => <<"user">>,
173+
<<"bucketBy">> => <<"null">>,
174+
<<"variations">> => [
175+
#{<<"variation">> => 0, <<"weight">> => 50000, <<"untracked">> => false},
176+
#{<<"variation">> => 1, <<"weight">> => 50000, <<"untracked">> => false}
177+
]
178+
}),
179+
#{key => <<"flagKey">>, salt => <<"flagSalt">>},
180+
ldclient_context:set(<<"null">>, null, ldclient_context:new(<<"user-key">>))).

0 commit comments

Comments
 (0)