Fix product slug: extract from URL path instead of g.post_slug
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 53s

App-level preprocessor pops slug then page_slug into g.post_slug,
overwriting the product slug with the page slug ("market"). Extract
the product slug directly from the request path after "/product/".

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
giles
2026-02-24 10:12:00 +00:00
parent 97bc694ff0
commit 25228881aa

View File

@@ -25,9 +25,17 @@ def register():
bp = Blueprint("product", __name__, url_prefix="/product/<slug>") bp = Blueprint("product", __name__, url_prefix="/product/<slug>")
@bp.url_value_preprocessor @bp.url_value_preprocessor
def pull_blog(endpoint, values): def pull_blog(endpoint, values):
# App-level preprocessor pops "slug" into g.post_slug before this runs, # App-level preprocessor pops both "slug" and "page_slug" into g.post_slug,
# so values.get("slug") is None. Fall back to g.post_slug. # with page_slug overwriting slug. We need the original product slug which
g.product_slug = values.get("slug") or getattr(g, "post_slug", None) # the app preprocessor popped first — but it's gone. Instead, extract the
# product slug from the request path: .../product/<slug>/...
from quart import request as req
parts = req.path.rstrip("/").split("/")
try:
idx = parts.index("product")
g.product_slug = parts[idx + 1] if idx + 1 < len(parts) else None
except (ValueError, IndexError):
g.product_slug = None
# ───────────────────────────────────────────────────────────── # ─────────────────────────────────────────────────────────────
# BEFORE REQUEST: Slug or numeric ID resolver # BEFORE REQUEST: Slug or numeric ID resolver