# HG changeset patch # User Marcin Kuzminski # Date 2020-03-30 09:08:33 # Node ID 0d8d4107caed3e4e128dc9e4f08688d5299f98dc # Parent cf6613424d89ff7a70e78d744118184dba99afc1 exc-tracker: make context attribute behave like in API case - simplified how use of api attachment of the attributes is done so we can explicitly pass it. - for celery we need this else it fails to send emails diff --git a/rhodecode/lib/base.py b/rhodecode/lib/base.py --- a/rhodecode/lib/base.py +++ b/rhodecode/lib/base.py @@ -283,7 +283,7 @@ def get_current_lang(request): return getattr(request, '_LOCALE_', request.locale_name) -def attach_context_attributes(context, request, user_id=None): +def attach_context_attributes(context, request, user_id=None, is_api=None): """ Attach variables into template context called `c`. """ @@ -379,7 +379,8 @@ def attach_context_attributes(context, r "sideside": "sideside" }.get(request.GET.get('diffmode')) - is_api = hasattr(request, 'rpc_user') + if is_api is not None: + is_api = hasattr(request, 'rpc_user') session_attrs = { # defaults "clone_url_format": "http", diff --git a/rhodecode/lib/exc_tracking.py b/rhodecode/lib/exc_tracking.py --- a/rhodecode/lib/exc_tracking.py +++ b/rhodecode/lib/exc_tracking.py @@ -119,7 +119,10 @@ def send_exc_email(exc_id, exc_type_name log.debug('Sending Email exception to: `%s`', recipients or 'all super admins') # NOTE(marcink): needed for email template rendering - attach_context_attributes(TemplateArgs(), request, request.user.user_id) + user_id = None + if request: + user_id = request.user.user_id + attach_context_attributes(TemplateArgs(), request, user_id=user_id, is_api=True) email_kwargs = { 'email_prefix': app.CONFIG.get('exception_tracker.email_prefix', '') or '[RHODECODE ERROR]',