Let resolve_product run fully for POST, just skip redirects
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m0s

Instead of skipping resolve_product entirely for POST (leaving
g.item_data unset and breaking templates), run the full resolution
but suppress canonical-slug redirects. This sets g.item_data for
the context processor so d.slug and other template vars work.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
giles
2026-02-24 10:22:04 +00:00
parent e0b640f15b
commit 291c829c7f

View File

@@ -48,9 +48,7 @@ def register():
if raw_slug is None:
return
# POST endpoints (cart, like) only need the slug — skip redirects
if req.method == "POST":
return
is_post = req.method == "POST"
# 1. If slug is INT → load product by ID
if raw_slug.isdigit():
@@ -69,18 +67,22 @@ def register():
g.item_data = {"d": d, "slug": product["slug"], "liked": False}
return
# Not deleted → redirect to canonical slug
# Not deleted → redirect to canonical slug (GET only)
if not is_post:
canon = canonical_html_slug(product["slug"])
return redirect(
host_url(url_for("market.browse.product.product_detail", slug=canon))
)
g.item_data = {"d": product, "slug": product["slug"], "liked": False}
return
# 2. Normal slug-based behaviour
if is_product_blocked(raw_slug):
abort(404)
canon = canonical_html_slug(raw_slug)
if canon != raw_slug:
if canon != raw_slug and not is_post:
return redirect(
host_url(url_for("market.browse.product.product_detail", slug=canon))
)
@@ -91,7 +93,7 @@ def register():
)
if not d:
abort(404)
g.item_data = {"d": d, "slug": canon, "liked": d["is_liked"]}
g.item_data = {"d": d, "slug": canon, "liked": d.get("is_liked", False)}
@bp.context_processor
def context():
@@ -265,7 +267,6 @@ def register():
return await render_template(
"_types/product/_added.html",
d={"slug": slug},
cart=g.cart,
item=ci,
total=total,