Skip to content

Commit

Permalink
Add guard condition to prevent intermittent KeyError
Browse files Browse the repository at this point in the history
There are some circumstances where the context dictionary does not contain a
"request" item. In those cases we get a KeyError, for example:

  KeyError /clerk/api/email/{pk}/{email_id}/attachment/{attachment_id}/sharepoint/
  Level: Error
  Unhandled 'request'

Those circumstances are unclear however. It seems to be related to the issue
that was addressed in commit da95495 but I
cannot reproduce it. This change seems like a reasonable precaution until we
have more information.
  • Loading branch information
luca-vari committed Jun 28, 2024
1 parent da95495 commit 8166f16
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/web/templatetags/cookie.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

@register.simple_tag(takes_context=True)
def get_cookie(context, cookie_name):
request = context["request"]
result = request.COOKIES.get(cookie_name, '')
return result
request = context.get("request")
if request:
return request.COOKIES.get(cookie_name, "")
return ""

0 comments on commit 8166f16

Please sign in to comment.