Azure-Functions icon indicating copy to clipboard operation
Azure-Functions copied to clipboard

[UX] - Portal cannot execute timer triggered functions if the argument name is '_'

Open madushans opened this issue 6 years ago • 10 comments

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.e 0 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.

madushans avatar Nov 14 '20 12:11 madushans

FYI @ehamai can we get someone to take a look?

btardif avatar May 06 '21 22:05 btardif

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

v-anvari avatar Jun 15 '21 13:06 v-anvari

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.

UniSnake avatar Apr 07 '22 21:04 UniSnake

Still the same behavior using .net 6 and Runtime version 4

robi26 avatar Jul 21 '22 13:07 robi26

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

madushans avatar Sep 27 '22 03:09 madushans

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.

Dav-id-V avatar Oct 24 '22 13:10 Dav-id-V

@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

btardif avatar Nov 03 '22 20:11 btardif

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/ with Postman.

Changing the parameter name back to "timer" from "_" fixes the problem.

lfalck avatar Dec 16 '22 12:12 lfalck

Also seeing this issue on the generated "Code + Test" test tab on the portal. Using an HttpTrigger with an HttpRequestMessage parameter named "_".

L-E-son avatar Dec 20 '22 02:12 L-E-son

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".

jozkee avatar Sep 25 '24 17:09 jozkee