|
12 | 12 | # limitations under the License. |
13 | 13 |
|
14 | 14 | from __future__ import annotations |
15 | | -from typing import TYPE_CHECKING, NamedTuple, Optional, Sequence, List, TypedDict |
| 15 | +from typing import TYPE_CHECKING, NamedTuple, Optional, Sequence, List, TypedDict, Dict |
16 | 16 |
|
17 | 17 | from . import bucketer |
18 | 18 | from . import entities |
@@ -83,6 +83,7 @@ class Decision(NamedTuple): |
83 | 83 | variation: Optional[entities.Variation] |
84 | 84 | source: Optional[str] |
85 | 85 | cmab_uuid: Optional[str] |
| 86 | + holdout: Optional[Dict[str, str]] |
86 | 87 |
|
87 | 88 |
|
88 | 89 | class DecisionService: |
@@ -744,7 +745,7 @@ def get_decision_for_flag( |
744 | 745 |
|
745 | 746 | def get_variation_for_holdout( |
746 | 747 | self, |
747 | | - holdout: dict[str, str], |
| 748 | + holdout: Dict[str, str], |
748 | 749 | user_context: OptimizelyUserContext, |
749 | 750 | project_config: ProjectConfig |
750 | 751 | ) -> DecisionResult: |
@@ -806,14 +807,23 @@ def get_variation_for_holdout( |
806 | 807 | decide_reasons.extend(bucket_reasons) |
807 | 808 |
|
808 | 809 | if variation: |
| 810 | + # For holdouts, variation is a dict, not a Variation entity |
| 811 | + variation_key = variation['key'] if isinstance(variation, dict) else variation.key |
809 | 812 | message = ( |
810 | | - f"The user '{user_id}' is bucketed into variation '{variation['key']}' " |
| 813 | + f"The user '{user_id}' is bucketed into variation '{variation_key}' " |
811 | 814 | f"of holdout '{holdout['key']}'." |
812 | 815 | ) |
813 | 816 | self.logger.info(message) |
814 | 817 | decide_reasons.append(message) |
815 | 818 |
|
816 | | - holdout_decision = Decision(holdout, variation, enums.DecisionSources.HOLDOUT, None) |
| 819 | + # Create Decision with holdout - experiment is None, holdout field contains the holdout dict |
| 820 | + holdout_decision: Decision = Decision( |
| 821 | + experiment=None, |
| 822 | + variation=None, |
| 823 | + source=enums.DecisionSources.HOLDOUT, |
| 824 | + cmab_uuid=None, |
| 825 | + holdout=holdout |
| 826 | + ) |
817 | 827 | return { |
818 | 828 | 'decision': holdout_decision, |
819 | 829 | 'error': False, |
|
0 commit comments