fix: auto-create PageConfig when enabling page features
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 36s

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 <noreply@anthropic.com>
This commit is contained in:
giles
2026-02-10 23:34:18 +00:00
parent af260872d1
commit 8fad1ecc7d

View File

@@ -74,12 +74,14 @@ def register():
post_id = post["id"] post_id = post["id"]
# Load PageConfig # Load or create PageConfig
pc = (await g.s.execute( pc = (await g.s.execute(
sa_select(PageConfig).where(PageConfig.post_id == post_id) sa_select(PageConfig).where(PageConfig.post_id == post_id)
)).scalar_one_or_none() )).scalar_one_or_none()
if pc is 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 # Parse request body
body = await request.get_json() body = await request.get_json()
@@ -139,7 +141,9 @@ def register():
sa_select(PageConfig).where(PageConfig.post_id == post_id) sa_select(PageConfig).where(PageConfig.post_id == post_id)
)).scalar_one_or_none() )).scalar_one_or_none()
if pc is 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 form = await request.form
merchant_code = (form.get("merchant_code") or "").strip() merchant_code = (form.get("merchant_code") or "").strip()