Skip to content

Unexpected behavior when a null label occurs in the middle of a set of selects #349

Description

Problem

When using multiple Selects chained together, putting a null labeled select in the middle causes that to take precedence even if a future label should have overridden it.

Example

Given the following Keys in AAC:

image

And the following code:

void Main()
{
	IConfigurationRoot root = new ConfigurationBuilder()
              .AddAzureAppConfiguration(opts =>
              {
	              opts.ConfigureClientOptions(o => o.Diagnostics.IsLoggingEnabled = true);
	              var credential = new DefaultAzureCredential(new DefaultAzureCredentialOptions());
              
	              var aac = opts.Connect(new Uri("urlgoeshere"), credential);
	              aac.TrimKeyPrefix("Test:");
	              aac
		              .Select(KeyFilter.Any, "Development") // Gets all Keys with Development label
		              .Select(KeyFilter.Any, "WyzaTest") // Overrides any keys with WyzaTest label
		              .Select("Test:*") // Selects any keys starting with "Test:*" with no label
		              .Select("Test:*", "Development") // Selects any keys starting with "Test:*" with Development label
		              .Select("Test:*", "WyzaTest"); // Selects any keys starting with "Test:*" with WyzaTest label
	              aac.ConfigureKeyVault(kv => kv.SetCredential(credential));
              }).Build();
										
	System.Console.WriteLine(root.GetValue<string>("WyzaTest"));
}

The expected outcome should be that the word "boo" is written to the console because the very last selector of Test:* with label WyzaTest should have matched. Instead the actual result is that it returns true which is what the (no label) value is for that key.

If I change the selection to this, then it will properly resolve to boo as expected. Of course the layers of overrides won't quite behave the same way in this scenario since the goal was to override non-prefixed keys with their prefixed versions if they existed even if they didn't have a label.

		              .Select("Test:*") // Selects any keys starting with "Test:*" with no label
		              .Select(KeyFilter.Any, "Development") // Gets all Keys with Development label
		              .Select(KeyFilter.Any, "WyzaTest") // Overrides any keys with WyzaTest label
		              .Select("Test:*", "Development") // Selects any keys starting with "Test:*" with Development label
		              .Select("Test:*", "WyzaTest"); // Selects any keys starting with "Test:*" with WyzaTest label

If this really is the intended behavior, then I suggest something be added in to prevent (or warn) you from selecting a \0 label after any non-null label selection as it won't behave in the way that one might expect.

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions