Skip to content

Conversation

@bokelley
Copy link
Contributor

@bokelley bokelley commented Nov 4, 2025

Summary

Fixed issue where custom targeting keys weren't showing as pre-selected when editing a product. The keys were saved correctly but the edit form wasn't displaying them.

Problem

When you:

  1. Create a product with custom targeting keys (e.g., sport=basketball)
  2. Save the product
  3. Edit the product again

The custom targeting dropdown was empty instead of showing the previously selected keys.

Root Cause

The edit_product GET handler wasn't passing targeting_template to the template. The custom targeting keys were stored in implementation_config.custom_targeting_keys, but the form expects them in targeting_template.key_value_pairs.

Fix

Added logic to populate targeting_template from implementation_config when loading the edit form:

  1. Parse both targeting_template and implementation_config from product
  2. If targeting_template.key_value_pairs is empty but implementation_config.custom_targeting_keys exists, copy the keys
  3. Pass the populated targeting_template to the template

This provides backwards compatibility for products that have keys stored only in implementation_config.

Test Coverage

  • ✅ Unit tests: 861 passed
  • ✅ Integration tests: 32 passed
  • ✅ Integration V2 tests: 28 passed
  • ✅ All pre-commit hooks passed

Result

  • ✅ Custom targeting keys now show as pre-selected when editing products
  • ✅ Form correctly displays existing key/value pairs
  • ✅ Backwards compatible with existing products

🤖 Generated with Claude Code

**Problem:**
When editing a product with custom targeting keys, the keys weren't showing
as pre-selected in the targeting dropdown. The form displayed correctly but
the existing values weren't loaded.

**Root Cause:**
The edit_product function wasn't passing targeting_template to the template.
Custom targeting keys were stored in implementation_config but the form
expects them in targeting_template.key_value_pairs.

**Fix:**
- Parse targeting_template from product model
- If targeting_template is empty but implementation_config has custom_targeting_keys,
  populate targeting_template.key_value_pairs from implementation_config
- Pass targeting_template to the template so the form can pre-select values

**Result:**
- Custom targeting keys now show as pre-selected when editing products
- Backwards compatible with products that have keys in implementation_config only
- Form properly displays existing custom key/value pairs

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
@bokelley bokelley merged commit 88f0b9e into main Nov 4, 2025
10 checks passed
danf-newton pushed a commit to Newton-Research-Inc/salesagent that referenced this pull request Nov 24, 2025
…rotocol#693)

**Problem:**
When editing a product with custom targeting keys, the keys weren't showing
as pre-selected in the targeting dropdown. The form displayed correctly but
the existing values weren't loaded.

**Root Cause:**
The edit_product function wasn't passing targeting_template to the template.
Custom targeting keys were stored in implementation_config but the form
expects them in targeting_template.key_value_pairs.

**Fix:**
- Parse targeting_template from product model
- If targeting_template is empty but implementation_config has custom_targeting_keys,
  populate targeting_template.key_value_pairs from implementation_config
- Pass targeting_template to the template so the form can pre-select values

**Result:**
- Custom targeting keys now show as pre-selected when editing products
- Backwards compatible with products that have keys in implementation_config only
- Form properly displays existing custom key/value pairs

🤖 Generated with Claude Code

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants