Skip resolve_product redirects for POST requests (cart, like)
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 2m4s

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 <noreply@anthropic.com>
This commit is contained in:
giles
2026-02-24 10:06:05 +00:00
parent d014203776
commit 97bc694ff0

View File

@@ -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)