@@ -204,6 +204,8 @@ def __str__(self):
204
204
205
205
206
206
class FunctionBuilder (object ):
207
+ function_bindings : dict = {}
208
+
207
209
def __init__ (self , func , function_script_file ):
208
210
self ._function = Function (func , function_script_file )
209
211
@@ -232,6 +234,12 @@ def _validate_function(self,
232
234
"""
233
235
Validates the function information before building the function.
234
236
237
+ Functions with the same function name are not supported and should
238
+ fail indexing. If a function name is not defined, the default is the
239
+ method name. This also means that two functions with the same
240
+ method name will also fail indexing.
241
+ https://github.com/Azure/azure-functions-python-worker/issues/1489
242
+
235
243
:param auth_level: Http auth level that will be set if http
236
244
trigger function auth level is None.
237
245
"""
@@ -262,6 +270,16 @@ def _validate_function(self,
262
270
parse_singular_param_to_enum (auth_level , AuthLevel ))
263
271
self ._function ._is_http_function = True
264
272
273
+ # This dict contains the function name and its bindings for all
274
+ # functions in an app. If a previous function has the same name,
275
+ # indexing will fail here.
276
+ if self .function_bindings .get (function_name , None ):
277
+ raise ValueError (
278
+ f"Function { function_name } does not have a unique"
279
+ f" function name. Please change @app.function_name() or"
280
+ f" the function method name to be unique." )
281
+ self .function_bindings [function_name ] = bindings
282
+
265
283
def build (self , auth_level : Optional [AuthLevel ] = None ) -> Function :
266
284
"""
267
285
Validates and builds the function object.
@@ -3333,11 +3351,13 @@ class ExternalHttpFunctionApp(
3333
3351
@abc .abstractmethod
3334
3352
def _add_http_app (self ,
3335
3353
http_middleware : Union [
3336
- AsgiMiddleware , WsgiMiddleware ]) -> None :
3354
+ AsgiMiddleware , WsgiMiddleware ],
3355
+ function_name : str = 'http_app_func' ) -> None :
3337
3356
"""Add a Wsgi or Asgi app integrated http function.
3338
3357
3339
3358
:param http_middleware: :class:`WsgiMiddleware`
3340
3359
or class:`AsgiMiddleware` instance.
3360
+ :param function_name: name for the function
3341
3361
3342
3362
:return: None
3343
3363
"""
@@ -3346,17 +3366,18 @@ def _add_http_app(self,
3346
3366
3347
3367
class AsgiFunctionApp (ExternalHttpFunctionApp ):
3348
3368
def __init__ (self , app ,
3349
- http_auth_level : Union [AuthLevel , str ] = AuthLevel .FUNCTION ):
3369
+ http_auth_level : Union [AuthLevel , str ] = AuthLevel .FUNCTION ,
3370
+ function_name : str = 'http_app_func' ):
3350
3371
"""Constructor of :class:`AsgiFunctionApp` object.
3351
3372
3352
3373
:param app: asgi app object.
3353
3374
:param http_auth_level: Determines what keys, if any, need to be
3354
- present
3355
- on the request in order to invoke the function.
3375
+ present on the request in order to invoke the function.
3376
+ :param function_name: function name
3356
3377
"""
3357
3378
super ().__init__ (auth_level = http_auth_level )
3358
3379
self .middleware = AsgiMiddleware (app )
3359
- self ._add_http_app (self .middleware )
3380
+ self ._add_http_app (self .middleware , function_name )
3360
3381
self .startup_task_done = False
3361
3382
3362
3383
def __del__ (self ):
@@ -3365,7 +3386,8 @@ def __del__(self):
3365
3386
3366
3387
def _add_http_app (self ,
3367
3388
http_middleware : Union [
3368
- AsgiMiddleware , WsgiMiddleware ]) -> None :
3389
+ AsgiMiddleware , WsgiMiddleware ],
3390
+ function_name : str = 'http_app_func' ) -> None :
3369
3391
"""Add an Asgi app integrated http function.
3370
3392
3371
3393
:param http_middleware: :class:`WsgiMiddleware`
@@ -3379,6 +3401,7 @@ def _add_http_app(self,
3379
3401
3380
3402
asgi_middleware : AsgiMiddleware = http_middleware
3381
3403
3404
+ @self .function_name (name = function_name )
3382
3405
@self .http_type (http_type = 'asgi' )
3383
3406
@self .route (methods = (method for method in HttpMethod ),
3384
3407
auth_level = self .auth_level ,
@@ -3395,21 +3418,25 @@ async def http_app_func(req: HttpRequest, context: Context):
3395
3418
3396
3419
class WsgiFunctionApp (ExternalHttpFunctionApp ):
3397
3420
def __init__ (self , app ,
3398
- http_auth_level : Union [AuthLevel , str ] = AuthLevel .FUNCTION ):
3421
+ http_auth_level : Union [AuthLevel , str ] = AuthLevel .FUNCTION ,
3422
+ function_name : str = 'http_app_func' ):
3399
3423
"""Constructor of :class:`WsgiFunctionApp` object.
3400
3424
3401
3425
:param app: wsgi app object.
3426
+ :param function_name: function name
3402
3427
"""
3403
3428
super ().__init__ (auth_level = http_auth_level )
3404
- self ._add_http_app (WsgiMiddleware (app ))
3429
+ self ._add_http_app (WsgiMiddleware (app ), function_name )
3405
3430
3406
3431
def _add_http_app (self ,
3407
3432
http_middleware : Union [
3408
- AsgiMiddleware , WsgiMiddleware ]) -> None :
3433
+ AsgiMiddleware , WsgiMiddleware ],
3434
+ function_name : str = 'http_app_func' ) -> None :
3409
3435
"""Add a Wsgi app integrated http function.
3410
3436
3411
3437
:param http_middleware: :class:`WsgiMiddleware`
3412
3438
or class:`AsgiMiddleware` instance.
3439
+ :param function_name: name for the function
3413
3440
3414
3441
:return: None
3415
3442
"""
@@ -3419,6 +3446,7 @@ def _add_http_app(self,
3419
3446
3420
3447
wsgi_middleware : WsgiMiddleware = http_middleware
3421
3448
3449
+ @self .function_name (function_name )
3422
3450
@self .http_type (http_type = 'wsgi' )
3423
3451
@self .route (methods = (method for method in HttpMethod ),
3424
3452
auth_level = self .auth_level ,
0 commit comments