Skip to content

Commit 12c04b2

Browse files
Exclude user_id and userId from custom data in all cases
Co-authored-by: jonathan <[email protected]>
1 parent 330a3d6 commit 12c04b2

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

devcycle_python_sdk/models/user.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ def create_user_from_context(
130130
private_custom_data: Dict[str, Any] = {}
131131
if context and context.attributes:
132132
for key, value in context.attributes.items():
133-
# Skip user_id and userId if they were used as the user ID
134-
if key == "user_id" and user_id_source == "user_id":
133+
# Skip user_id and userId - these are reserved for user ID mapping
134+
if key == "user_id":
135135
continue
136-
if key == "userId" and user_id_source == "userId":
136+
if key == "userId":
137137
continue
138138

139139
if value is not None:

test/models/test_user.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,31 +96,33 @@ def test_create_user_from_context_user_id_priority(self):
9696
user = DevCycleUser.create_user_from_context(context)
9797
self.assertEqual(user.user_id, userId)
9898

99-
def test_create_user_from_context_userId_in_custom_data_when_not_used(self):
99+
def test_create_user_from_context_user_id_fields_always_excluded(self):
100100
targeting_key_id = "targeting-12345"
101101
userId = "userId-12345"
102+
user_id = "user_id-12345"
102103

103-
# When targeting_key is used, userId should be in custom data
104+
# When targeting_key is used, both user_id and userId should be excluded from custom data
104105
context = EvaluationContext(
105106
targeting_key=targeting_key_id,
106-
attributes={"userId": userId, "other_field": "value"}
107+
attributes={"user_id": user_id, "userId": userId, "other_field": "value"}
107108
)
108109
user = DevCycleUser.create_user_from_context(context)
109110
self.assertEqual(user.user_id, targeting_key_id)
110111
self.assertIsNotNone(user.customData)
111-
self.assertEqual(user.customData["userId"], userId)
112+
self.assertNotIn("user_id", user.customData)
113+
self.assertNotIn("userId", user.customData)
112114
self.assertEqual(user.customData["other_field"], "value")
113115

114-
# When user_id is used, userId should be in custom data
115-
user_id = "user_id-12345"
116+
# When user_id is used, userId should still be excluded from custom data
116117
context = EvaluationContext(
117118
targeting_key=None,
118119
attributes={"user_id": user_id, "userId": userId, "other_field": "value"}
119120
)
120121
user = DevCycleUser.create_user_from_context(context)
121122
self.assertEqual(user.user_id, user_id)
122123
self.assertIsNotNone(user.customData)
123-
self.assertEqual(user.customData["userId"], userId)
124+
self.assertNotIn("user_id", user.customData)
125+
self.assertNotIn("userId", user.customData)
124126
self.assertEqual(user.customData["other_field"], "value")
125127

126128
def test_create_user_from_context_userId_excluded_when_used(self):

0 commit comments

Comments
 (0)