Repository navigation
fix(flags): defer an index-less group filter in a person condition #413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
marandaneto
merged 3 commits into
main
from
fix/flags-indexless-group-filter-person-condition
Dec 2, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
cdad71c
fix(flags): defer an index-less group filter in a person condition
marandaneto d81dac9
chore: add PostHog.AspNetCore changeset for the index-less group filt…
marandaneto dd4072d
fix(flags): report an index-less group filter in a person condition i…
marandaneto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
.changeset/index-less-group-filter-person-condition-aspnetcore.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "PostHog.AspNetCore": patch | ||
| --- | ||
|
|
||
| Picks up the `PostHog` fix for a `group` property filter without `group_type_index` in a person-aggregated condition. With local evaluation, the PostHog feature manager no longer matches such a filter against person properties. The flag falls back to the server instead. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "PostHog": patch | ||
| --- | ||
|
|
||
| Local evaluation now leaves a flag unresolved with the `unsupported_definition` reason when a person-aggregated condition has a `group` property filter without `group_type_index`, so the flag falls back to the server. Before, the filter was matched against person properties and could return a local result that the server contradicts. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| using PostHog; | ||
| using PostHog.Api; | ||
| using PostHog.Features; | ||
| using UnitTests.Fakes; | ||
|
|
||
| namespace LocalEvaluatorTests; | ||
|
|
||
| public class TheIndexLessGroupFilter | ||
| { | ||
| const string TierEnterprise = """{"key": "tier", "type": "group", "operator": "exact", "value": "enterprise"}"""; | ||
| const string TierNotSet = """{"key": "tier", "type": "group", "operator": "is_not_set"}"""; | ||
|
|
||
| // conditionAggregation is the condition's aggregation_group_type_index JSON, or empty to omit it. | ||
| static string Definitions(string filter, string flagAggregation, string conditionAggregation) => $$$""" | ||
| { | ||
| "flags": [{"key": "legacy-tier", "active": true, "filters": { | ||
| {{{flagAggregation}}} | ||
| "groups": [{ {{{conditionAggregation}}} "properties": [{{{filter}}}], "rollout_percentage": 100}] | ||
| }}], | ||
| "group_type_mapping": {"0": "organization"} | ||
| } | ||
| """; | ||
|
|
||
| sealed record Evaluation(bool? Flag, IReadOnlyDictionary<string, UnresolvedFlagReason> UnresolvedFlags, int RemoteRequests); | ||
|
|
||
| static async Task<Evaluation> EvaluateAsync(string definitions, FeatureFlagOptions options) | ||
| { | ||
| var container = new TestContainer("fake-personal-api-key"); | ||
| container.FakeHttpMessageHandler.AddLocalEvaluationResponseWithETag(definitions, "\"definitions\""); | ||
| var remoteHandler = container.FakeHttpMessageHandler.AddFlagsResponse( | ||
| """{"featureFlags": {"legacy-tier": false}}"""); | ||
| await using var client = container.Activate<PostHogClient>(); | ||
|
|
||
| var snapshot = await client.EvaluateFlagsAsync("user", options, CancellationToken.None); | ||
|
|
||
| return new Evaluation( | ||
| snapshot.GetFlag("legacy-tier")?.IsEnabled, | ||
| snapshot.UnresolvedFlags.ToDictionary(pair => pair.Key, pair => pair.Value), | ||
| remoteHandler.ReceivedRequests.Count); | ||
| } | ||
|
|
||
| static GroupCollection Acme(Dictionary<string, object?>? properties = null) | ||
| => [new Group("organization", "acme", properties ?? [])]; | ||
|
|
||
| static FeatureFlagOptions BothSetToEnterprise(bool onlyEvaluateLocally) => new() | ||
| { | ||
| OnlyEvaluateLocally = onlyEvaluateLocally, | ||
| PersonProperties = new() { ["tier"] = "enterprise" }, | ||
| Groups = Acme(new() { ["tier"] = "enterprise" }) | ||
| }; | ||
|
|
||
| static FeatureFlagOptions BothListedKnownAbsent(bool onlyEvaluateLocally) => new() | ||
| { | ||
| OnlyEvaluateLocally = onlyEvaluateLocally, | ||
| Groups = Acme(), | ||
| PersonPropertyKeysKnownAbsent = ["tier"], | ||
| GroupPropertyKeysKnownAbsent = new Dictionary<string, IReadOnlyCollection<string>> { ["organization"] = ["tier"] } | ||
| }; | ||
|
|
||
| // A person flag with the condition aggregation omitted, and a group flag whose condition sets it to null. | ||
| public static TheoryData<string, string> PersonConditions() => new() | ||
| { | ||
| { "", "" }, | ||
| { "\"aggregation_group_type_index\": 0,", "\"aggregation_group_type_index\": null," } | ||
| }; | ||
|
|
||
| [Theory] | ||
| [MemberData(nameof(PersonConditions))] | ||
| public async Task IsUnresolvedInAPersonConditionWhenPropertiesAreSupplied(string flagAggregation, string conditionAggregation) | ||
| { | ||
| foreach (var filter in new[] { TierEnterprise, TierNotSet }) | ||
| { | ||
| var result = await EvaluateAsync( | ||
| Definitions(filter, flagAggregation, conditionAggregation), | ||
| BothSetToEnterprise(onlyEvaluateLocally: true)); | ||
|
|
||
| Assert.Null(result.Flag); | ||
| Assert.Equal(UnresolvedFlagReason.UnsupportedDefinition, result.UnresolvedFlags["legacy-tier"]); | ||
| Assert.Equal(0, result.RemoteRequests); | ||
| } | ||
| } | ||
|
|
||
| [Theory] | ||
| [MemberData(nameof(PersonConditions))] | ||
| public async Task IsUnresolvedInAPersonConditionWhenTheKeyIsKnownAbsent(string flagAggregation, string conditionAggregation) | ||
| { | ||
| foreach (var filter in new[] { TierEnterprise, TierNotSet }) | ||
| { | ||
| var result = await EvaluateAsync( | ||
| Definitions(filter, flagAggregation, conditionAggregation), | ||
| BothListedKnownAbsent(onlyEvaluateLocally: true)); | ||
|
|
||
| Assert.Null(result.Flag); | ||
| Assert.Equal(UnresolvedFlagReason.UnsupportedDefinition, result.UnresolvedFlags["legacy-tier"]); | ||
| } | ||
| } | ||
|
|
||
| [Theory] | ||
| [MemberData(nameof(PersonConditions))] | ||
| public async Task FallsBackToTheServerInAPersonCondition(string flagAggregation, string conditionAggregation) | ||
| { | ||
| var result = await EvaluateAsync( | ||
| Definitions(TierEnterprise, flagAggregation, conditionAggregation), | ||
| BothSetToEnterprise(onlyEvaluateLocally: false)); | ||
|
|
||
| Assert.False(result.Flag); | ||
| Assert.Equal(1, result.RemoteRequests); | ||
| } | ||
|
|
||
| [Theory] | ||
| [MemberData(nameof(PersonConditions))] | ||
| public async Task ReportsAPersonConditionInTheDefinitionReason(string flagAggregation, string conditionAggregation) | ||
| { | ||
| var evaluator = await CreateEvaluatorAsync(Definitions(TierEnterprise, flagAggregation, conditionAggregation)); | ||
|
|
||
| Assert.Equal( | ||
| UnresolvedFlagReason.UnsupportedDefinition, | ||
| evaluator.GetDefinitionUnresolvedReason(evaluator.LocalEvaluationApiResult.Flags[0])); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData("\"aggregation_group_type_index\": 0,", "")] | ||
| [InlineData("", "\"aggregation_group_type_index\": 0,")] | ||
| public async Task DoesNotReportAGroupConditionInTheDefinitionReason(string flagAggregation, string conditionAggregation) | ||
| { | ||
| var evaluator = await CreateEvaluatorAsync(Definitions(TierEnterprise, flagAggregation, conditionAggregation)); | ||
|
|
||
| Assert.Null(evaluator.GetDefinitionUnresolvedReason(evaluator.LocalEvaluationApiResult.Flags[0])); | ||
| } | ||
|
|
||
| static async Task<LocalEvaluator> CreateEvaluatorAsync(string definitions) => | ||
| new((await PostHog.Json.JsonSerializerHelper.DeserializeFromCamelCaseJsonStringAsync<LocalEvaluationApiResult>(definitions))!); | ||
|
|
||
| [Theory] | ||
| [InlineData("\"aggregation_group_type_index\": 0,", "")] | ||
| [InlineData("", "\"aggregation_group_type_index\": 0,")] | ||
| public async Task ReadsTheConditionGroupTypeInAGroupCondition(string flagAggregation, string conditionAggregation) | ||
| { | ||
| var result = await EvaluateAsync( | ||
| Definitions(TierEnterprise, flagAggregation, conditionAggregation), | ||
| new FeatureFlagOptions | ||
| { | ||
| OnlyEvaluateLocally = true, | ||
| PersonProperties = new() { ["tier"] = "free" }, | ||
| Groups = Acme(new() { ["tier"] = "enterprise" }) | ||
| }); | ||
|
|
||
| Assert.True(result.Flag); | ||
| Assert.Empty(result.UnresolvedFlags); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.