From 05fa3647e565195dd4506f3f0c533f77f46ea916 Mon Sep 17 00:00:00 2001 From: Samir Boulahtit Date: Tue, 25 Nov 2025 21:22:28 +0100 Subject: [PATCH] fix: correct base_url calculation in error renderer for path-based routing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix error page links not respecting vendor context in path-based routing by aligning with the pattern used throughout the codebase. Problem: - Error pages showed links like /shop/ instead of /vendors/wizamart/shop/ - error_renderer.py was checking request.state.access_method (never set) - This meant access_method was always None, so base_url defaulted to "/" - Links ignored vendor context and broke multi-access routing Root Cause: - Inconsistent pattern: error_renderer.py used wrong attribute - Rest of codebase (6 locations) correctly uses vendor_context.get('detection_method') - No code ever sets request.state.access_method anywhere Solution: - Change from: access_method = getattr(request.state, "access_method", None) - Change to: access_method = vendor_context.get('detection_method', 'unknown') - Aligns with pattern used in: * app/exceptions/handler.py:384 (login redirect) * main.py:336 (root redirect) * app/routes/shop_pages.py:85, 391 (shop pages) * app/api/v1/shop/auth.py:159, 223 (auth endpoints) Changes: - Line 263-264: Get vendor_context first, then extract detection_method from it - Line 266: Now correctly detects path-based access method - base_url now properly set to /vendors/wizamart/ for path-based routing Impact: - ✅ Path-based routing: /vendors/wizamart/shop123 → links to /vendors/wizamart/shop/ - ✅ Direct shop access: /shop/test → links to /shop/ (unchanged) - ✅ No breaking changes (access_method was never used before) - ✅ Consistent with entire codebase pattern Testing: - curl http://localhost:8000/vendors/wizamart/shop123 Before: href="/shop/" (wrong) After: href="/vendors/wizamart/shop/" (correct) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app/exceptions/error_renderer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/exceptions/error_renderer.py b/app/exceptions/error_renderer.py index 0642121b..ac574cd4 100644 --- a/app/exceptions/error_renderer.py +++ b/app/exceptions/error_renderer.py @@ -260,8 +260,8 @@ class ErrorPageRenderer: } # Calculate base_url for shop links - access_method = getattr(request.state, "access_method", None) vendor_context = getattr(request.state, "vendor_context", None) + access_method = vendor_context.get('detection_method', 'unknown') if vendor_context else 'unknown' base_url = "/" if access_method == "path" and vendor: # Use the full_prefix from vendor_context to determine which pattern was used