Skip to content

Commit

Permalink
Fix LoggedModel.thread.request not being cleared in failing tests (#1727
Browse files Browse the repository at this point in the history
)
  • Loading branch information
he3lixxx authored Mar 28, 2022
1 parent 1da41f7 commit 0eec302
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions evap/evaluation/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ def __call__(self, request):
LoggedModel.thread.request = request
LoggedModel.thread.request_id = str(uuid.uuid4())

response = self.get_response(request)

del LoggedModel.thread.request
del LoggedModel.thread.request_id
try:
# django documentation says to just do this without the try, and that exceptions will be handled:
# https://docs.djangoproject.com/en/4.0/topics/http/middleware/#writing-your-own-middleware
# However, django-webtest sets DEBUG_PROPAGATE_EXCEPTIONS, and propagated exceptions caused our deletion to
# be skipped, leading to weird errors in the tests executed afterwards. See #1727.
response = self.get_response(request)
finally:
del LoggedModel.thread.request
del LoggedModel.thread.request_id

return response

0 comments on commit 0eec302

Please sign in to comment.