Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch No Request Context in Log Extra Middleware #1399

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions ckanext/canada/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from ckan.plugins.toolkit import (
c,
g,
h,
chained_action,
ValidationError,
Expand Down Expand Up @@ -702,11 +703,15 @@ def __init__(self, app, config):
def __call__(self, environ, start_response):
def _start_response(status, response_headers, exc_info=None):
extra = []
if c.user:
log_extra = c.log_extra if hasattr(c, 'log_extra') else u''
try:
contextual_user = g.user
except TypeError:
contextual_user = None
if contextual_user:
log_extra = g.log_extra if hasattr(g, 'log_extra') else u''
extra = [(
'X-LogExtra', u'user={uid} {extra}'.format(
uid=c.user,
uid=contextual_user,
extra=log_extra).encode('utf-8')
)
]
Expand Down
Loading