04/17 Update: fixed email ingestion ticket error 3
This commit is contained in:
+8
-1
@@ -147,10 +147,17 @@ def create_app(config_name=None):
|
|||||||
# ── Context processors ────────────────────────────────────────────────────
|
# ── Context processors ────────────────────────────────────────────────────
|
||||||
@app.context_processor
|
@app.context_processor
|
||||||
def inject_globals():
|
def inject_globals():
|
||||||
|
from flask import has_request_context
|
||||||
from flask_login import current_user
|
from flask_login import current_user
|
||||||
from app.models import SystemSetting
|
from app.models import SystemSetting
|
||||||
unread = 0
|
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
|
from app.models import Notification
|
||||||
unread = Notification.query.filter_by(
|
unread = Notification.query.filter_by(
|
||||||
user_id=current_user.id, is_read=False
|
user_id=current_user.id, is_read=False
|
||||||
|
|||||||
Reference in New Issue
Block a user