Skip to content

Commit a5f2aca

Browse files
committed
fix(cohorts): return the Amplitude list ID at every depth their parsers read
1 parent 0f0e09a commit a5f2aca

3 files changed

Lines changed: 37 additions & 3 deletions

File tree

api/cohorts/sync_views.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,18 @@
2222
)
2323

2424
_LIST_RESPONSE = inline_serializer(
25-
"AmplitudeListResponse", {"list_id": serializers.UUIDField()}
25+
"AmplitudeListResponse",
26+
{
27+
"list_id": serializers.UUIDField(),
28+
"listId": serializers.UUIDField(),
29+
"response": inline_serializer(
30+
"AmplitudeListResponseEnvelope",
31+
{
32+
"list_id": serializers.UUIDField(),
33+
"listId": serializers.UUIDField(),
34+
},
35+
),
36+
},
2637
)
2738

2839
_MIXPANEL_RESPONSE = inline_serializer(
@@ -73,7 +84,21 @@ def create(self, request: Request) -> Response:
7384
name=serializer.validated_data["name"],
7485
source_type=CohortSourceType.AMPLITUDE,
7586
)
76-
return Response({"list_id": str(cohort.uuid)})
87+
# Amplitude's Testing tab and production sync worker read the list
88+
# ID from this body differently: the Testing tab wraps the body in a
89+
# {"response": ...} envelope before applying the configured ID path,
90+
# while the production worker appears to ignore the configured path
91+
# and read the documented default key, camelCase "listId". Carrying
92+
# the ID at every spelling and depth satisfies every parser
93+
# observed.
94+
list_id = str(cohort.uuid)
95+
return Response(
96+
{
97+
"list_id": list_id,
98+
"listId": list_id,
99+
"response": {"list_id": list_id, "listId": list_id},
100+
}
101+
)
77102

78103
@action(detail=True, methods=["POST"])
79104
def add(self, request: Request, pk: str) -> Response:

api/tests/unit/cohorts/test_sync_views.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ def test_amplitude_create_list__valid_key__creates_amplitude_cohort(
5151
# Then
5252
assert response.status_code == status.HTTP_200_OK
5353
cohort = Cohort.objects.get(uuid=response.json()["list_id"])
54+
# Amplitude's test and production parsers read the ID under different
55+
# keys and depths; every copy must be present.
56+
body = response.json()
57+
assert (
58+
body["listId"]
59+
== body["response"]["list_id"]
60+
== body["response"]["listId"]
61+
== body["list_id"]
62+
)
5463
assert cohort.environment == key.environment
5564
assert cohort.source_type == CohortSourceType.AMPLITUDE
5665
assert cohort.segment.name == "[Amplitude] Beta users: 1234"

docs/docs/deployment-self-hosting/observability/_events-catalogue.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ Attributes:
166166
### `cohorts.sync_webhook.rejected`
167167

168168
Logged at `warning` from:
169-
- `api/cohorts/sync_views.py:214`
169+
- `api/cohorts/sync_views.py:239`
170170

171171
Attributes:
172172
- `action`

0 commit comments

Comments
 (0)