fix: Make psycopg2 optional for Flask/Werkzeug compatibility

- Bump Flask requirement to >=3.0.0 (required for Werkzeug 3.x)
- Make psycopg2 import conditional in routes/adsb.py and utils/adsb_history.py
- ADS-B history features gracefully disabled when PostgreSQL libs unavailable

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Smittix
2026-01-29 22:19:14 +00:00
parent 7b847e0541
commit 872cc806eb
4 changed files with 493 additions and 476 deletions

View File

@@ -26,7 +26,7 @@ classifiers = [
"Topic :: System :: Networking :: Monitoring",
]
dependencies = [
"flask>=2.0.0",
"flask>=3.0.0",
"skyfield>=1.45",
"pyserial>=3.5",
"Werkzeug>=3.1.5",

View File

@@ -1,5 +1,5 @@
# Core dependencies
flask>=2.0.0
flask>=3.0.0
flask-limiter>=2.5.4
requests>=2.28.0
Werkzeug>=3.1.5

File diff suppressed because it is too large Load Diff

View File

@@ -9,8 +9,16 @@ import time
from datetime import datetime, timezone
from typing import Iterable
import psycopg2
from psycopg2.extras import execute_values, Json
# psycopg2 is optional - only needed for PostgreSQL history persistence
try:
import psycopg2
from psycopg2.extras import execute_values, Json
PSYCOPG2_AVAILABLE = True
except ImportError:
psycopg2 = None # type: ignore
execute_values = None # type: ignore
Json = None # type: ignore
PSYCOPG2_AVAILABLE = False
from config import (
ADSB_DB_HOST,
@@ -199,7 +207,7 @@ class AdsbHistoryWriter:
"""Background writer for ADS-B history records."""
def __init__(self) -> None:
self.enabled = ADSB_HISTORY_ENABLED
self.enabled = ADSB_HISTORY_ENABLED and PSYCOPG2_AVAILABLE
self._queue: queue.Queue[dict] = queue.Queue(maxsize=ADSB_HISTORY_QUEUE_SIZE)
self._thread: threading.Thread | None = None
self._stop_event = threading.Event()
@@ -297,7 +305,7 @@ class AdsbSnapshotWriter:
"""Background writer for ADS-B snapshot records."""
def __init__(self) -> None:
self.enabled = ADSB_HISTORY_ENABLED
self.enabled = ADSB_HISTORY_ENABLED and PSYCOPG2_AVAILABLE
self._queue: queue.Queue[dict] = queue.Queue(maxsize=ADSB_HISTORY_QUEUE_SIZE)
self._thread: threading.Thread | None = None
self._stop_event = threading.Event()