Skip to content

Commit 442b8b1

Browse files
Update missing filter handling to treat is as disabled when requirement all (#590)
1 parent 46aa3de commit 442b8b1

2 files changed

Lines changed: 14 additions & 14 deletions

File tree

src/Microsoft.FeatureManagement/FeatureManager.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -418,15 +418,6 @@ private async ValueTask<bool> IsEnabledAsync<TContext>(FeatureDefinition feature
418418
}
419419
else
420420
{
421-
//
422-
// Ensure no conflicts in the feature definition
423-
if (featureDefinition.RequirementType == RequirementType.All && _options.IgnoreMissingFeatureFilters)
424-
{
425-
throw new FeatureManagementException(
426-
FeatureManagementError.Conflict,
427-
$"The 'IgnoreMissingFeatureFilters' flag cannot be used in combination with a feature of requirement type 'All'.");
428-
}
429-
430421
//
431422
// If the requirement type is all, we default to true. Requirement type All will end on a false
432423
enabled = featureDefinition.RequirementType == RequirementType.All;
@@ -491,6 +482,15 @@ private async ValueTask<bool> IsEnabledAsync<TContext>(FeatureDefinition feature
491482

492483
Logger?.LogWarning(FeatureFilterNotFoundError, featureFilterConfiguration.Name, featureDefinition.Name);
493484

485+
//
486+
// If requirement type is All, a missing filter means the feature cannot be enabled
487+
if (featureDefinition.RequirementType == RequirementType.All)
488+
{
489+
enabled = false;
490+
491+
break;
492+
}
493+
494494
continue;
495495
}
496496

tests/Tests.FeatureManagement/FeatureManagementTest.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ public async Task UsesRequirementType()
796796
}
797797

798798
[Fact]
799-
public async Task RequirementTypeAllExceptions()
799+
public async Task RequirementTypeAllWithIgnoreMissingFeatureFilters()
800800
{
801801
IConfiguration config = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
802802

@@ -816,12 +816,12 @@ public async Task RequirementTypeAllExceptions()
816816

817817
IFeatureManager featureManager = serviceProvider.GetRequiredService<IFeatureManager>();
818818

819+
//
820+
// AllFilterFeature has RequirementType.All with missing filters.
821+
// With IgnoreMissingFeatureFilters enabled, the feature should be treated as disabled.
819822
string allFilterFeature = Features.AllFilterFeature;
820823

821-
await Assert.ThrowsAsync<FeatureManagementException>(async () =>
822-
{
823-
await featureManager.IsEnabledAsync(allFilterFeature);
824-
});
824+
Assert.False(await featureManager.IsEnabledAsync(allFilterFeature));
825825
}
826826

827827
[Fact]

0 commit comments

Comments
 (0)