learningequality / kolibri

Kolibri Learning Platform: the offline app for universal education
https://learningequality.org/kolibri/
MIT License
780 stars 648 forks source link

Only call render on the response if it has a render method #10506

Closed sentry-io[bot] closed 7 months ago

sentry-io[bot] commented 1 year ago

AttributeError: 'HttpResponseNotAllowed' object has no attribute 'render'

Sentry Issue: KOLIBRI-BACKEND-2BQ

AttributeError: 'HttpResponseNotAllowed' object has no attribute 'render'
(3 additional frame(s) were not displayed)
...
  File "django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "django/utils/decorators.py", line 67, in _wrapper
    return bound_func(*args, **kwargs)
  File "django/views/decorators/http.py", line 99, in inner
    response = func(request, *args, **kwargs)
  File "kolibri/core/decorators.py", line 374, in inner_func
    render_and_cache(response, CACHE_KEY_TEMPLATE.format(request.path))
  File "kolibri/core/decorators.py", line 342, in render_and_cache
    response.render()
KshitijThareja commented 8 months ago

@rtibbles It's just a simple fix according to me. We just have to check whether the response object has the render attribute or not before calling response.render() in the render_and_cache function. Could you please assign this issue to me? Thanks :)

rtibbles commented 8 months ago

Yes, checking it has the attribute render and that it is callable should be good, see a similar example here https://github.com/learningequality/kolibri/blob/release-v0.16.x/kolibri/core/content/api.py#L135

MisRob commented 7 months ago

Closed by https://github.com/learningequality/kolibri/pull/11762