From 8fad1ecc7d25f1d2039afc04161c003fa85619b1 Mon Sep 17 00:00:00 2001 From: giles Date: Tue, 10 Feb 2026 23:34:18 +0000 Subject: [PATCH] fix: auto-create PageConfig when enabling page features When toggling market/calendar features or saving SumUp settings, create a PageConfig row if one doesn't exist yet instead of returning a 404 error. Co-Authored-By: Claude Opus 4.6 --- bp/post/admin/routes.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bp/post/admin/routes.py b/bp/post/admin/routes.py index 5e1accd..afe6ab6 100644 --- a/bp/post/admin/routes.py +++ b/bp/post/admin/routes.py @@ -74,12 +74,14 @@ def register(): post_id = post["id"] - # Load PageConfig + # Load or create PageConfig pc = (await g.s.execute( sa_select(PageConfig).where(PageConfig.post_id == post_id) )).scalar_one_or_none() if pc is None: - return jsonify({"error": "PageConfig not found for this page."}), 404 + pc = PageConfig(post_id=post_id, features={}) + g.s.add(pc) + await g.s.flush() # Parse request body body = await request.get_json() @@ -139,7 +141,9 @@ def register(): sa_select(PageConfig).where(PageConfig.post_id == post_id) )).scalar_one_or_none() if pc is None: - return jsonify({"error": "PageConfig not found for this page."}), 404 + pc = PageConfig(post_id=post_id, features={}) + g.s.add(pc) + await g.s.flush() form = await request.form merchant_code = (form.get("merchant_code") or "").strip()