From 9524a24715914a6847634a24ff631562ee3635ed Mon Sep 17 00:00:00 2001 From: "Troll (Hermes Agent)" Date: Wed, 5 Aug 2026 03:04:48 +0000 Subject: [PATCH] Fix TypeError when loading max_revisions from settings JSON The customer player page (/play/) and revision endpoint were reading max_revisions directly from booth_settings.json, where it is stored as a string. Arithmetic/comparison with revision_count (an int) raised TypeError and caused a 500 error when opening the customer player. Add get_max_revisions() helper that always returns a non-negative int, and use it in play(), revise(), and admin_settings(). --- app.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/app.py b/app.py index 9d3d310..2306716 100644 --- a/app.py +++ b/app.py @@ -309,6 +309,16 @@ def get_kiosk_mode(): return 'cycle' +def get_max_revisions(): + """Return the effective max revisions as an integer.""" + cfg = load_booth_settings() + try: + val = int(cfg.get('max_revisions', current_app.config.get('MAX_REVISIONS', 2))) + except (ValueError, TypeError): + val = current_app.config.get('MAX_REVISIONS', 2) + return max(0, val) + + def get_hermes_api_key(): """ Return the effective Hermes API key. @@ -606,8 +616,7 @@ def play(token): abort(404) # Load runtime max revisions setting. - runtime_settings = load_booth_settings() - max_revisions = runtime_settings.get('max_revisions', current_app.config['MAX_REVISIONS']) + max_revisions = get_max_revisions() revisions_left = max(0, max_revisions - (req.get('revision_count') or 0)) return render_template('player.html', req=req, revisions_left=revisions_left) @@ -647,8 +656,7 @@ def revise(token): abort(404) # Enforce max revisions limit for customer-submitted revisions. - runtime_settings = load_booth_settings() - max_revisions = runtime_settings.get('max_revisions', current_app.config['MAX_REVISIONS']) + max_revisions = get_max_revisions() current_count = req.get('revision_count') or 0 if current_count >= max_revisions: flash('Revision limit reached. Please speak to the booth operator if you need further changes.', 'error') @@ -1151,7 +1159,7 @@ def admin_settings(): # Load persistent runtime settings (max_revisions overrides env var if set). runtime_settings = load_booth_settings() - current_max_revisions = runtime_settings.get('max_revisions', current_app.config.get('MAX_REVISIONS', 2)) + current_max_revisions = get_max_revisions() current_refresh_seconds = runtime_settings.get('refresh_seconds', 10) booth_open = runtime_settings.get('booth_open', True)