azure-webjobs-sdk icon indicating copy to clipboard operation
azure-webjobs-sdk copied to clipboard

AzureWebJobs.<Function-Name>.Disabled value evaluation is case-sensitive

Open fume opened this issue 5 years ago • 3 comments
trafficstars

Please provide a succinct description of the issue.

Repro steps

Provide the steps required to reproduce the problem

  1. Create a FunctionApp with at least a function in it

  2. Disable the function via UI in the portal

  3. The AzureWebJobs.FunctionName.Disabled Configuration Key is created with a value of true

  4. The function is correctly disabled

  5. Change the AzureWebJobs.FunctionName.Disabled configuration value to True (uppercase T) via Configuration blade

  6. The function is Enabled again!

Expected behavior

True and true should be treated in the same way, disabling the function.

Actual behavior

True is considered as a falsy value and the function is not disabled as expected.

Known workarounds

Use lowercase values: true and false

Related information

This is not a big problem while managing functions via Azure Portal as it writes the AzureWebJobs.FunctionName.Disabled config correctly (lowercase). This is really a big issue when using ARM Templates because boolean parameters are written as True/False (T/F uppercase, string representations of booleans) in the AppSettings. A workaround is to use string/int parameters in ARM templates, but it doesn't really make sense for what should be a boolean param.

Example of ARM Template that will "fail" (schema, dependsOn, etc, are omitted on purpose for brevity):

{
  "parameters": {
    "function_disabled": {
      "type": "bool",
      "defaultValue": true
    }
  },
  "resources": [
    {
      "type": "Microsoft.Web/sites/config",
      "apiVersion": "2016-08-01",
      "name": "functionappname/appsettings",
      "location": "westeurope",
      "properties": {
        "AzureWebJobs.MyFunction.Disabled": "[parameters('function_disabled')]"
      }
    }
  ]
}          

This ARM template will produce the AzureWebJobs.MyFunction.Disabled AppSettings with a value of True or False depending on the function_disabled parameter value. If the parameter function_disabled is false, everything works as expected because False is not truthy (or at least, is not equal to true), but if function_disabled is true then you would expect MyFunction to be disabled, while it's not.

I'm searching for the sourcecode that uses the AzureWebJobs..Disabled settings, but i guess that it is just checking if that config is equals to true, checking it as a string. I would expect that the parameter is bool-parsed first, but maybe it's not.

thanks, regards

EDIT Maybe this is the "guilty" guy: https://github.com/Azure/azure-webjobs-sdk/blob/00bc34086ed262fcb3b23739d11246661bfe0a17/src/Microsoft.Azure.WebJobs.Host/ConfigurationUtility.cs#L37

This seems to be case insensitive (OrdinalIgnoreCase), so everything should work as expected....but it doesn't :(

fume avatar Jun 06 '20 05:06 fume

hi, any update?

thanks a lot, regards

fume avatar Jul 30 '20 23:07 fume

Hi @fume , Apologies for the delayed response, we shall look into this scenario, if this is by-design and the case sensitive can be ignored.

v-anvari avatar Mar 05 '21 16:03 v-anvari

Hi @fume, Thank you for bringing this to notice.

Adding this issue to Traiged for update, as it is a bug. The Boolean expression needs to be parsed, which seems to be missing.

public static bool IsSettingEnabled(string settingName)

cc @brettsam / @alrod , Can you please confirm if this was an intentional change or requires update

v-anvari avatar Mar 08 '21 17:03 v-anvari