From 97bc694ff07108a0508b50e727b32b7e70ebada9 Mon Sep 17 00:00:00 2001 From: giles Date: Tue, 24 Feb 2026 10:06:05 +0000 Subject: [PATCH] Skip resolve_product redirects for POST requests (cart, like) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit resolve_product's canonical slug redirect causes a 302 loop on POST /cart/ because it redirects to the GET product detail page. POST endpoints only need g.product_slug to look up the product — skip the full resolution/redirect logic. Co-Authored-By: Claude Opus 4.6 --- bp/product/routes.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bp/product/routes.py b/bp/product/routes.py index f4b71df..959ce5f 100644 --- a/bp/product/routes.py +++ b/bp/product/routes.py @@ -34,10 +34,16 @@ def register(): # ───────────────────────────────────────────────────────────── @bp.before_request async def resolve_product(): + from quart import request as req + raw_slug = g.product_slug = getattr(g, "product_slug", None) if raw_slug is None: return + # POST endpoints (cart, like) only need the slug — skip redirects + if req.method == "POST": + return + # 1. If slug is INT → load product by ID if raw_slug.isdigit(): product_id = int(raw_slug)