mirror of
https://github.com/MarekWo/mc-webui.git
synced 2026-08-08 09:42:55 +02:00
fix(v2): Use Flask current_app for DeviceManager lookup in cli.py
The module-level 'from app.main import device_manager' was returning None in Flask request context even though device_manager was set. Now tries current_app.device_manager first (Flask app context), falling back to module import for non-request contexts. Fixes 500 errors on /api/contacts, /api/contacts/pending, /api/contacts/detailed, and /api/channels endpoints. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+9
-1
@@ -19,7 +19,15 @@ class MeshCLIError(Exception):
|
||||
|
||||
|
||||
def _get_dm():
|
||||
"""Get the DeviceManager instance (deferred import to avoid circular refs)."""
|
||||
"""Get the DeviceManager instance — try Flask app context first, then module global."""
|
||||
try:
|
||||
from flask import current_app
|
||||
dm = getattr(current_app, 'device_manager', None)
|
||||
if dm is not None:
|
||||
return dm
|
||||
except RuntimeError:
|
||||
pass # Outside of Flask request context
|
||||
|
||||
from app.main import device_manager
|
||||
if device_manager is None:
|
||||
raise MeshCLIError("DeviceManager not initialized")
|
||||
|
||||
Reference in New Issue
Block a user