Skip to content

Commit ab19267

Browse files
fix: return the Amplitude list ID at every depth their parsers read (#8399)
Co-authored-by: flagsmith-engineering[bot] <flagsmith-engineering[bot]@users.noreply.github.com>
1 parent bbc4bd1 commit ab19267

4 files changed

Lines changed: 56 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`

openapi.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18946,7 +18946,26 @@ components:
1894618946
list_id:
1894718947
type: string
1894818948
format: uuid
18949+
listId:
18950+
type: string
18951+
format: uuid
18952+
response:
18953+
$ref: '#/components/schemas/AmplitudeListResponseEnvelope'
18954+
required:
18955+
- listId
18956+
- list_id
18957+
- response
18958+
AmplitudeListResponseEnvelope:
18959+
type: object
18960+
properties:
18961+
list_id:
18962+
type: string
18963+
format: uuid
18964+
listId:
18965+
type: string
18966+
format: uuid
1894918967
required:
18968+
- listId
1895018969
- list_id
1895118970
AuditLogList:
1895218971
type: object

0 commit comments

Comments
 (0)