I came across an AttributeError due the usage of functools.partial() because of the missing view_func.__name__ attribute which is necessary in the little utils.py. functools.partial() generated functions don't have these argument.
Expected behavior
Expected is at least some kind of error handling instead of breaking the application.
Log Message
2023-08-02 09:39:20,730 - ERROR - log - Internal Server Error: /api/openapi.json
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/django/core/handlers/exception.py", line 56, in inner
response = get_response(request)
File "/usr/local/lib/python3.10/dist-packages/django/core/handlers/base.py", line 185, in _get_response
response = middleware_method(
File "/usr/local/lib/python3.10/dist-packages/autodynatrace/wrappers/django/middlewares.py", line 49, in process_view
name = func_name(view_func)
File "/usr/local/lib/python3.10/dist-packages/autodynatrace/wrappers/utils.py", line 2, in func_name
return view_func.__name__
AttributeError: 'functools.partial' object has no attribute '__name__'
Idea
The name of the initial function can be found in the partial arguments partial.func.__name__. So a possible solution could be:
def func_name(view_func):
try:
name = view_func.__name__
except AttributeError:
try:
name = view_func.func.__name__
except AttributeError:
name = "unknown_function"
return name
I'm not sure if this is "generic" enough. Looking forward to your feedback.
Describe the bug
I came across an
AttributeError
due the usage of functools.partial() because of the missingview_func.__name__
attribute which is necessary in the little utils.py. functools.partial() generated functions don't have these argument.Expected behavior Expected is at least some kind of error handling instead of breaking the application.
Log Message
Idea The name of the initial function can be found in the partial arguments
partial.func.__name__
. So a possible solution could be:I'm not sure if this is "generic" enough. Looking forward to your feedback.
Cheerio, Stephan