Skip to content

Commit e252a36

Browse files
fix: return only listId from Amplitude list creation (#8400)
Co-authored-by: flagsmith-engineering[bot] <flagsmith-engineering[bot]@users.noreply.github.com>
1 parent ab19267 commit e252a36

4 files changed

Lines changed: 10 additions & 60 deletions

File tree

api/cohorts/sync_views.py

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

2424
_LIST_RESPONSE = inline_serializer(
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-
},
25+
"AmplitudeListResponse", {"listId": serializers.UUIDField()}
3726
)
3827

3928
_MIXPANEL_RESPONSE = inline_serializer(
@@ -84,21 +73,10 @@ def create(self, request: Request) -> Response:
8473
name=serializer.validated_data["name"],
8574
source_type=CohortSourceType.AMPLITUDE,
8675
)
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-
)
76+
# Amplitude's production sync worker reads the list ID from its
77+
# documented default key, camelCase "listId", ignoring the response
78+
# path configured in the Integration Portal.
79+
return Response({"listId": str(cohort.uuid)})
10280

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

api/tests/unit/cohorts/test_sync_views.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,7 @@ def test_amplitude_create_list__valid_key__creates_amplitude_cohort(
5050

5151
# Then
5252
assert response.status_code == status.HTTP_200_OK
53-
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-
)
53+
cohort = Cohort.objects.get(uuid=response.json()["listId"])
6354
assert cohort.environment == key.environment
6455
assert cohort.source_type == CohortSourceType.AMPLITUDE
6556
assert cohort.segment.name == "[Amplitude] Beta users: 1234"
@@ -83,7 +74,7 @@ def test_amplitude_create_list__postgres_environment__creates_cohort(
8374

8475
# Then
8576
assert response.status_code == status.HTTP_200_OK
86-
cohort = Cohort.objects.get(uuid=response.json()["list_id"])
77+
cohort = Cohort.objects.get(uuid=response.json()["listId"])
8778
assert cohort.environment == environment
8879

8980

@@ -359,7 +350,7 @@ def test_amplitude_create_list__valid_key__audits_and_queues_environment_update(
359350
# Then - the audit record carries no user, names the source, and is the
360351
# hook that rebuilds the environment document.
361352
assert response.status_code == status.HTTP_200_OK
362-
cohort = Cohort.objects.get(uuid=response.json()["list_id"])
353+
cohort = Cohort.objects.get(uuid=response.json()["listId"])
363354
audit_log = AuditLog.objects.get(related_object_id=cohort.segment_id)
364355
assert audit_log.author is None
365356
assert audit_log.master_api_key is None
@@ -386,7 +377,7 @@ def test_amplitude_create_list__valid_key__history_records_no_user(
386377
# Then - a machine caller leaves no user on historical records; stamping
387378
# one would fail, since the sync key is not a Flagsmith user.
388379
assert response.status_code == status.HTTP_200_OK
389-
cohort = Cohort.objects.get(uuid=response.json()["list_id"])
380+
cohort = Cohort.objects.get(uuid=response.json()["listId"])
390381
history_record = cohort.segment.history.get()
391382
assert history_record.history_user is None
392383
assert history_record.master_api_key is None

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:239`
169+
- `api/cohorts/sync_views.py:217`
170170

171171
Attributes:
172172
- `action`

openapi.yaml

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18943,30 +18943,11 @@ components:
1894318943
AmplitudeListResponse:
1894418944
type: object
1894518945
properties:
18946-
list_id:
18947-
type: string
18948-
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
1896418946
listId:
1896518947
type: string
1896618948
format: uuid
1896718949
required:
1896818950
- listId
18969-
- list_id
1897018951
AuditLogList:
1897118952
type: object
1897218953
properties:

0 commit comments

Comments
 (0)