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:
MarekWo
2026-03-24 08:26:07 +01:00
parent 5ccd882c5a
commit f9bcbabb86
2 changed files with 6 additions and 6 deletions

View File

@@ -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:

View File

@@ -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():