-
Notifications
You must be signed in to change notification settings - Fork 252
Open
Description
Using django-prometheus 1.0.9 with django 1.11.2.
I have some django-rest-framework views that are being cached with the cache_page decorator like:
@method_decorator(cache_page(settings.CACHE_TIMEOUT_API))
def dispatch(self, *args, **kwargs):
return super(BaseAPICachedView, self).dispatch(*args, **kwargs)
When there is a cache hit, the django-prometheus middleware fails in middleware.py:135 with AttributeError: 'Response' object has no attribute 'template_name'
def process_template_response(self, request, response):
responses_by_templatename.labels(str(
response.template_name)).inc()
return response
Sure enough, the cached views don't seem to have template_name. I fixed it by checking for the attribute first, not sure if that's the best way but it works for me:
def process_template_response(self, request, response):
if hasattr(response, 'template_name'):
responses_by_templatename.labels(str(
response.template_name)).inc()
return response
telminov and elnappo
Metadata
Metadata
Assignees
Labels
No labels