From a22244a041fa9fd5b07cb6ff1ef2f39c32ccf80c Mon Sep 17 00:00:00 2001 From: Smittix Date: Sat, 28 Feb 2026 17:29:10 +0000 Subject: [PATCH] fix: make flask-limiter import optional to prevent worker boot failure flask-limiter may not be installed (e.g. RPi venv). The hard import crashed the gunicorn gevent worker on startup, causing all routes to return 404 with no visible error. Now falls back to a no-op limiter. Co-Authored-By: Claude Opus 4.6 --- app.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/app.py b/app.py index 9fedb75..f1870be 100644 --- a/app.py +++ b/app.py @@ -42,8 +42,12 @@ from utils.constants import ( QUEUE_MAX_SIZE, ) import logging -from flask_limiter import Limiter -from flask_limiter.util import get_remote_address +try: + from flask_limiter import Limiter + from flask_limiter.util import get_remote_address + _has_limiter = True +except ImportError: + _has_limiter = False # Track application start time for uptime calculation import time as _time _app_start_time = _time.time() @@ -53,12 +57,21 @@ logger = logging.getLogger('intercept.database') app = Flask(__name__) app.secret_key = "signals_intelligence_secret" # Required for flash messages -# Set up rate limiting -limiter = Limiter( - key_func=get_remote_address, # Identifies the user by their IP - app=app, - storage_uri="memory://", # Use RAM memory (change to redis:// etc. for distributed setups) -) +# Set up rate limiting (optional — flask-limiter may not be installed) +if _has_limiter: + limiter = Limiter( + key_func=get_remote_address, + app=app, + storage_uri="memory://", + ) +else: + class _NoopLimiter: + """Fallback when flask-limiter is not installed.""" + def limit(self, *args, **kwargs): + def decorator(f): + return f + return decorator + limiter = _NoopLimiter() # Disable Werkzeug debugger PIN (not needed for local development tool) os.environ['WERKZEUG_DEBUG_PIN'] = 'off'