Skip to content

Commit 048601e

Browse files
authored
fix: stop duplicating distinct_id in flags person properties (#254)
* fix: stop duplicating distinct_id in flags person properties * fix: stop duplicating distinct_id in flags person properties * chore: update SDK test harness to 0.10.0
1 parent bbc2260 commit 048601e

6 files changed

Lines changed: 17 additions & 12 deletions

File tree

.changeset/quiet-wolves-fix.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"PostHog": patch
3+
"PostHog.AspNetCore": patch
4+
---
5+
6+
Stop duplicating `distinct_id` inside `/flags` person properties.

.github/workflows/sdk-compliance.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ on:
1414
jobs:
1515
compliance:
1616
name: PostHog SDK compliance tests
17-
uses: PostHog/posthog-sdk-test-harness/.github/workflows/test-sdk-action.yml@68498bcf3ae95ac941476e6ca3d42d6086e1c7fd
17+
uses: PostHog/posthog-sdk-test-harness/.github/workflows/test-sdk-action.yml@02c049e529001d02f37a534745678e057d371fb0
1818
with:
1919
adapter-dockerfile: "sdk_compliance_adapter/Dockerfile"
2020
adapter-context: "."
21-
test-harness-version: "0.9.0"
21+
test-harness-version: "0.10.0"

sdk_compliance_adapter/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ docker run -d --name sdk-adapter --network test-network -p 8080:8080 posthog-dot
3535
docker run --rm \
3636
--name test-harness \
3737
--network test-network \
38-
ghcr.io/posthog/sdk-test-harness:0.9.0 \
38+
ghcr.io/posthog/sdk-test-harness:0.10.0 \
3939
run --adapter-url http://sdk-adapter:8080 --mock-url http://test-harness:8081
4040

4141
# Cleanup

sdk_compliance_adapter/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ services:
99

1010
# Test harness
1111
test-harness:
12-
image: ghcr.io/posthog/sdk-test-harness:0.9.0
12+
image: ghcr.io/posthog/sdk-test-harness:0.10.0
1313
command: ["run", "--adapter-url", "http://sdk-adapter:8080", "--mock-url", "http://test-harness:8081"]
1414
networks:
1515
- test-network

src/PostHog/Api/PostHogApiClient.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,7 @@ public async Task<ApiResult> SendEventAsync(
132132

133133
if (personProperties is { Count: > 0 })
134134
{
135-
var mergedPersonProperties = new Dictionary<string, object?>(personProperties);
136-
if (!mergedPersonProperties.ContainsKey("distinct_id"))
137-
{
138-
mergedPersonProperties["distinct_id"] = distinctUserId;
139-
}
140-
141-
payload["person_properties"] = mergedPersonProperties;
135+
payload["person_properties"] = personProperties;
142136
}
143137

144138
if (flagKeysToEvaluate is { Count: > 0 })

tests/UnitTests/Features/FeatureFlagsTests.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2283,7 +2283,7 @@ public async Task BooleanFeatureFlagPayloadsLocal()
22832283
public async Task BooleanFeatureFlagPayloadsFromDecide()
22842284
{
22852285
var container = new TestContainer();
2286-
container.FakeHttpMessageHandler.AddFlagsResponse(
2286+
var handler = container.FakeHttpMessageHandler.AddFlagsResponse(
22872287
"""
22882288
{"featureFlags": {"person-flag": true}, "featureFlagPayloads": {"person-flag": "300"}}
22892289
"""
@@ -2295,6 +2295,10 @@ public async Task BooleanFeatureFlagPayloadsFromDecide()
22952295
PersonProperties = new() { ["region"] = "USA" }
22962296
});
22972297
JsonAssert.Equal(300, result?.Payload);
2298+
using var document = JsonDocument.Parse(handler.GetReceivedRequestBody(indented: false));
2299+
var personProperties = document.RootElement.GetProperty("person_properties");
2300+
Assert.Equal("USA", personProperties.GetProperty("region").GetString());
2301+
Assert.False(personProperties.TryGetProperty("distinct_id", out _));
22982302
}
22992303

23002304
[Fact] // Ported from PostHog/posthog-python test_multivariate_feature_flag_payloads
@@ -2400,6 +2404,7 @@ public async Task CallsDecideWithFlagKeyToEvaluate(bool disableGeoIp)
24002404
Assert.Equal("fake-project-token", root.GetProperty("api_key").GetString());
24012405
Assert.Equal("some-distinct-id", root.GetProperty("distinct_id").GetString());
24022406
Assert.Empty(root.GetProperty("groups").EnumerateObject());
2407+
Assert.False(root.TryGetProperty("person_properties", out _));
24032408
Assert.Empty(root.GetProperty("group_properties").EnumerateObject());
24042409
Assert.Equal(disableGeoIp, root.GetProperty("geoip_disable").GetBoolean());
24052410
var flagKey = Assert.Single(root.GetProperty("flag_keys_to_evaluate").EnumerateArray());

0 commit comments

Comments
 (0)