Skip to content

Commit 89d00a7

Browse files
Fix holdout variation lookup in impression event creation
CRITICAL FIX: Holdout impression events were sending empty variation_key and variation_id in event payloads, causing fullstack compatibility suite failures. Root Cause: - user_event_factory.create_impression_event was using get_flag_variation() for all events when both flag_key and variation_id were present - get_flag_variation() only searches flag_variations_map (experiments/rollouts) - Holdout variations aren't in flag_variations_map, so lookup returned None - This caused impression events to have empty variation_key and variation_id The Fix: - Added rule_type check: exclude HOLDOUT from get_flag_variation() path - For holdouts: use get_variation_from_id_by_experiment_id() instead - This works because holdout variations are properly mapped in variation_id_map_by_experiment_id and variation_key_map_by_experiment_id Impact: - Holdout impression events now include correct variation_key and variation_id - Event metadata properly populated: rule_key, rule_type: holdout, variation_key - Fixes fullstack compatibility suite decide_holdouts.feature event validation - All 237 tests passing (194 optimizely + 8 event_factory + 35 holdout) Aligned with Swift SDK event creation behavior.
1 parent 3d68a24 commit 89d00a7

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

optimizely/event/user_event_factory.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,13 @@ def create_impression_event(
6969
if activated_experiment:
7070
experiment_id = activated_experiment.id
7171

72-
if variation_id and flag_key:
72+
if variation_id and flag_key and rule_type != enums.DecisionSources.HOLDOUT:
7373
# need this condition when we send events involving forced decisions
7474
# (F-to-D or E-to-D with any ruleKey/variationKey combinations)
75+
# But NOT for holdouts - they use experiment_id lookup instead
7576
variation = project_config.get_flag_variation(flag_key, 'id', variation_id)
7677
elif variation_id and experiment_id:
78+
# For holdouts, experiments, and rollouts - lookup by experiment/holdout ID
7779
variation = project_config.get_variation_from_id_by_experiment_id(experiment_id, variation_id)
7880

7981
event_context = user_event.EventContext(

0 commit comments

Comments
 (0)