04/17 Update: fixed email ingestion ticket error 3

This commit is contained in:
2026-04-17 15:24:58 -04:00
parent 225d874c05
commit 58b47590b8
+8 -1
View File
@@ -147,10 +147,17 @@ def create_app(config_name=None):
# ── Context processors ────────────────────────────────────────────────────
@app.context_processor
def inject_globals():
from flask import has_request_context
from flask_login import current_user
from app.models import SystemSetting
unread = 0
if current_user.is_authenticated:
# current_user is only resolvable inside an active request context.
# When render_template_string() is called from a background job (e.g.
# APScheduler email ingestion), there is no session to load from, so
# Flask-Login returns None — causing AttributeError on .is_authenticated.
# The has_request_context() guard makes the context processor safe for
# both web requests and background callers.
if has_request_context() and current_user.is_authenticated:
from app.models import Notification
unread = Notification.query.filter_by(
user_id=current_user.id, is_read=False