mirror of
https://github.com/MarekWo/mc-webui.git
synced 2026-03-28 17:42:45 +01:00
fix: use Flask current_app for DB access in read_status and contacts_cache
'from app.main import db' gets None because python -m app.main loads the module as __main__, creating a separate module instance from app.main. Use current_app.db (Flask app context) instead — same pattern as api.py. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -11,6 +11,7 @@ parse_advert_payload().
|
||||
import logging
|
||||
import math
|
||||
import struct
|
||||
from flask import current_app
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -18,9 +19,8 @@ _TYPE_LABELS = {0: 'COM', 1: 'COM', 2: 'REP', 3: 'ROOM', 4: 'SENS'}
|
||||
|
||||
|
||||
def _get_db():
|
||||
"""Get database instance (deferred import to avoid circular imports)."""
|
||||
from app.main import db
|
||||
return db
|
||||
"""Get database instance from Flask app context."""
|
||||
return getattr(current_app, 'db', None)
|
||||
|
||||
|
||||
def get_all_contacts() -> list:
|
||||
|
||||
@@ -7,14 +7,14 @@ All data is stored in the read_status table of the SQLite database.
|
||||
"""
|
||||
|
||||
import logging
|
||||
from flask import current_app
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _get_db():
|
||||
"""Get database instance (deferred import to avoid circular imports)."""
|
||||
from app.main import db
|
||||
return db
|
||||
"""Get database instance from Flask app context."""
|
||||
return getattr(current_app, 'db', None)
|
||||
|
||||
|
||||
def load_read_status():
|
||||
|
||||
Reference in New Issue
Block a user