Skip to content

Commit e1f2ec5

Browse files
[AI-FSSDK] [FSSDK-12750] Use attribute id instead of key for CMAB prediction requests (#520)
Co-authored-by: Farhan Anjum <Farhan.Anjum@optimizely.com>
1 parent a1e0da8 commit e1f2ec5

2 files changed

Lines changed: 7 additions & 8 deletions

File tree

optimizely/cmab/cmab_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def _filter_attributes(self, project_config: ProjectConfig,
163163
for attribute_id in cmab_attribute_ids:
164164
attribute = project_config.attribute_id_map.get(attribute_id)
165165
if attribute and attribute.key in user_attributes:
166-
filtered_user_attributes[attribute.key] = user_attributes[attribute.key]
166+
filtered_user_attributes[attribute.id] = user_attributes[attribute.key]
167167

168168
return filtered_user_attributes
169169

tests/test_cmab_service.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def setUp(self):
5151

5252
def test_returns_decision_from_cache_when_valid(self):
5353
expected_key = self.cmab_service._get_cache_key("user123", "exp1")
54-
expected_attributes = {"age": 25, "location": "USA"}
54+
expected_attributes = {"66": 25, "77": "USA"}
5555
expected_hash = self.cmab_service._hash_attributes(expected_attributes)
5656

5757
self.mock_cmab_cache.lookup.return_value = {
@@ -70,7 +70,7 @@ def test_returns_decision_from_cache_when_valid(self):
7070

7171
def test_ignores_cache_when_option_given(self):
7272
self.mock_cmab_client.fetch_decision.return_value = "varB"
73-
expected_attributes = {"age": 25, "location": "USA"}
73+
expected_attributes = {"66": 25, "77": "USA"}
7474

7575
decision, _ = self.cmab_service.get_decision(
7676
self.mock_project_config,
@@ -124,7 +124,7 @@ def test_new_decision_when_hash_changes(self):
124124
}
125125
self.mock_cmab_client.fetch_decision.return_value = "varE"
126126

127-
expected_attribute = {"age": 25, "location": "USA"}
127+
expected_attribute = {"66": 25, "77": "USA"}
128128
expected_hash = self.cmab_service._hash_attributes(expected_attribute)
129129
expected_key = self.cmab_service._get_cache_key("user123", "exp1")
130130

@@ -148,8 +148,8 @@ def test_new_decision_when_hash_changes(self):
148148

149149
def test_filter_attributes_returns_correct_subset(self):
150150
filtered = self.cmab_service._filter_attributes(self.mock_project_config, self.mock_user_context, "exp1")
151-
self.assertEqual(filtered["age"], 25)
152-
self.assertEqual(filtered["location"], "USA")
151+
self.assertEqual(filtered["66"], 25)
152+
self.assertEqual(filtered["77"], "USA")
153153

154154
def test_filter_attributes_empty_when_no_cmab(self):
155155
self.mock_project_config.experiment_id_map["exp1"].cmab = None
@@ -178,11 +178,10 @@ def test_only_cmab_attributes_passed_to_client(self):
178178
[OptimizelyDecideOption.IGNORE_CMAB_CACHE]
179179
)
180180

181-
# Verify only age and location are passed (attributes configured in setUp)
182181
self.mock_cmab_client.fetch_decision.assert_called_once_with(
183182
"exp1",
184183
self.mock_user_context.user_id,
185-
{"age": 25, "location": "USA"},
184+
{"66": 25, "77": "USA"},
186185
decision["cmab_uuid"]
187186
)
188187

0 commit comments

Comments
 (0)