[UX] - Portal cannot execute timer triggered functions if the argument name is '_'
Azure portal returns a 404 when executing TimerTriggered functions if the timer trigger argument is '_' (discard)
If you got here from Google, because Azure portal shows a 404 when trying to run your timer triggered function, check your cron expression. Your expression should have 6 segments for Azure Functions (i.e
0 0/* * * * *) not 5 (i.e0 0/* * * *)
Steps to Reproduce
- Create a TimerTrigger C# azure function
public class MyTestFunction
{
[FunctionName("MyTestFunction")]
public async Task Run([TimerTrigger("%MyTestFunction_Schedule%")] TimerInfo _)
{
// stuff
}
}
- Deploy to an azure functions app
- Navigate to yourapp > functions > function name > Code + Test
- Click on Test/Run button
- Click Run
Expected: 202 Accepted Actual: 404 Not Found
- Rename the parameter to 'timer'
public class MyTestFunction
{
[FunctionName("MyTestFunction")]
public async Task Run([TimerTrigger("%MyTestFunction_Schedule%")] TimerInfo timer)
{
// stuff
}
}
- redeploy to Azure and run as above.
- Azure portal shows '202 Accepted' and the function executes.
Additional Information
This appear to happen only on Azure portal. Running the function locally on the timer trigger works fine. I have not tested to see if the timer still fires when deployed to Azure.
Also not sure if this is only in the new UX. I have not tried this with the classic functions experience.
Why this is important
This may conflict with certain style rules for some teams. In most cases the TimerTrigger argument is not used, so it may trigger warnings/info about 'unused param' and the easiest 'fix' is to make it a discard, but this can cause the above issue with no warning and my confuse a person trying to manually execute the function from the portal at a later time.
FYI @ehamai can we get someone to take a look?
Hi @madushans , I have tried to reproduce this issue in Azure portal and Visual studio.
While trying in Azure portal, My function ran successfully when an argument "TimerInfo _" is passed as a binding parameter and returned a 202 accepted output.
While, trying to pass argument as binding parameter in visual studio, it throws me the following warning : _The 'Function2' function is in error: The binding name _ is invalid. Please assign a valid name to the binding."_. But, The Function still ran as per the schedule.
C# Timer trigger function executed at: 6/15/2021 7:04:00 PM [2021-06-15T13:34:00.035Z] Executed 'Function2' (Succeeded, Id=ff6392cc-265e-4a64-b841-5370bc50aff4, Duration=25ms)
Closing this issue, as the timer trigger is executing as expected in Azure portal and visual studio, please feel free to reach back to us in case of any query
I was able to reproduce this with a timer triggered function newly deployed to Azure. Used the technique described here https://docs.microsoft.com/en-us/azure/azure-functions/functions-manually-run-non-http to manually trigger the timer function. Got 404s until I changed my argument from [TimerTrigger("0 30 9 * * *")] TimerInfo _ to [TimerTrigger("0 30 9 * * *")] TimerInfo timer and redeploying at which point I got a 202.
My function was using .Net Core 3.1 and Microsoft.NET.Sdk.Functions 3.0.13.
Still the same behavior using .net 6 and Runtime version 4
This is usually due to a bad cron expression and not due to the parameter name.
Azure portal should consider handling this and showing a better error message.
see this answer https://stackoverflow.com/a/72514924/975887
Still the same behavior using .net 6 and Runtime version 4
I can confirm. Since we changed the code to ([TimerTrigger("0 0 */6 * * *", RunOnStartup = false)] TimerInfo _) instead of ([TimerTrigger("0 0 */6 * * *", RunOnStartup = false)] TimerInfo myTimer) the trigger stopped working and our function was no longer called. Once we changed back to "TimerInfo myTimer" the trigger function started working again.
@fabiocav I think this needs to be routed to the runtime if we think it's still a valid issue, the 404 is not being thrown from UX layer
I am also facing this issue with a function running .NET 6 on Linux.
I get a 404 both from the portal and when I try to start the function by calling the admin endpoint admin/functions/
Changing the parameter name back to "timer" from "_" fixes the problem.
Also seeing this issue on the generated "Code + Test" test tab on the portal. Using an HttpTrigger with an HttpRequestMessage parameter named "_".
I'm getting this error with an HttpTrigger locally.
The 'Function1' function is in error: The binding name _ is invalid. Please assign a valid name to the binding.
It should be safe to use discard (_ ) if the parameter is not used. It also conflicts with IDE rule "IDE006 Avoid unused parameters in your code".