Skip to content

Conversation

@muzahidul-opti
Copy link

@muzahidul-opti muzahidul-opti commented Feb 3, 2026

Summary

This PR implements experiment-specific holdout targeting by adding an experiments field to the Holdout data model. This enables holdouts to target specific experiments in addition to flags.

Changes Made

Holdout Entity (optimizely/entities.py):

  • Added experiments: List[str] field with default empty list
  • Added is_local property that returns True when experiments list is not empty
  • Maintains backward compatibility (experiments defaults to empty list)

Type Definitions (optimizely/helpers/types.py):

  • Added experiments: list[str] to HoldoutDict TypedDict

ProjectConfig (optimizely/project_config.py):

  • Added experiment_holdouts_map: Dict[str, List[Holdout]] for efficient experiment-to-holdout lookups
  • Updated holdout initialization to build experiment mappings
  • Added get_holdouts_for_experiment(experiment_id: str) -> List[Holdout] method

Tests (tests/test_config.py):

  • Added 11 comprehensive tests covering:
    • experiments field defaults and population
    • is_local property behavior
    • get_holdouts_for_experiment functionality
    • One-to-many and many-to-one experiment mappings
    • Insertion order preservation
    • Independence of experiment and flag mappings
    • Equality comparison including experiments field

Implementation Notes

  • Experiment mapping is built independently from flag mapping
  • A holdout can be both global (applies to all flags) AND target specific experiments
  • The is_local property helps identify experiment-specific holdouts
  • All existing tests continue to pass (97/97)

Test Results

```
✅ 97 tests passed in tests/test_config.py
✅ 48 tests passed in holdout-specific test files
```

Related

🤖 Generated with Claude Code

- Add experiments field to Holdout entity with default empty list
- Add is_local property that returns True when experiments list is not empty
- Add experiment_holdouts_map to ProjectConfig for experiment-to-holdout mappings
- Add get_holdouts_for_experiment method to retrieve holdouts for a specific experiment
- Add comprehensive unit tests covering all new functionality
- Ensure backward compatibility with existing holdout functionality

This enables experiment-specific holdouts to be identified and retrieved efficiently.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants