From ed77278d7fa97775e479013ac90084964d532d98 Mon Sep 17 00:00:00 2001 From: Brian O'Kelley Date: Thu, 16 Oct 2025 16:15:33 -0400 Subject: [PATCH] Fix 500 error on product add page by correcting error handler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed two issues in the add_product route: 1. Error handler was missing required template variables - The invalid ad unit ID error handler tried to render add_product_gam.html - Template requires: formats, currencies, inventory_synced, authorized_properties, property_tags - Error handler only passed: tenant_id, tenant_name, form_data, error - This caused a 500 error when rendering the template - Solution: Redirect to form instead of re-rendering to get proper context 2. Added tenant_name to GET handler for consistency - While not strictly required by the template, this maintains consistency - Prevents issues if template is updated to use tenant_name in the future The 500 error occurred when validation failed for ad unit IDs because the render_template call was missing the required context variables that the Jinja2 template expected (formats loop, currencies loop, etc.). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/admin/blueprints/products.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/admin/blueprints/products.py b/src/admin/blueprints/products.py index a04fa36a1..fee70c567 100644 --- a/src/admin/blueprints/products.py +++ b/src/admin/blueprints/products.py @@ -107,7 +107,11 @@ def get_creative_formats( ) format_dict = { - "id": fmt.format_id, # Use "id" to match database schema (AdCP spec) + "id": ( + fmt.format_id.id + if isinstance(fmt.format_id, object) and hasattr(fmt.format_id, "id") + else str(fmt.format_id) + ), # Extract string ID from FormatId object "agent_url": fmt.agent_url, "name": fmt.name, "type": fmt.type, @@ -552,13 +556,8 @@ def add_product(tenant_id): f"Use 'Browse Ad Units' to select valid ad units.", "error", ) - return render_template( - "add_product_gam.html", - tenant_id=tenant_id, - tenant_name=tenant.name, - form_data=form_data, - error="Invalid ad unit IDs", - ) + # Redirect to form instead of re-rendering to avoid missing context + return redirect(url_for("products.add_product", tenant_id=tenant_id)) base_config["targeted_ad_unit_ids"] = id_list @@ -787,6 +786,7 @@ def add_product(tenant_id): return render_template( "add_product_gam.html", tenant_id=tenant_id, + tenant_name=tenant.name, inventory_synced=inventory_synced, formats=get_creative_formats(tenant_id=tenant_id), authorized_properties=properties_list,