Skip to content

Conversation

@bokelley
Copy link
Contributor

@bokelley bokelley commented Nov 4, 2025

Summary

Fixed a critical bug where placements weren't being saved when editing GAM products because the save logic was nested inside an if line_item_type: check that never executed in automatic mode.

Root Cause

The GAM product configuration save logic (lines 1147-1209 in src/admin/blueprints/products.py) was inside an if line_item_type: conditional. Since the edit form uses automatic line item type selection (based on pricing model), the form doesn't submit a line_item_type field. This caused the entire block to be skipped, preventing placements, ad units, targeting, and other GAM config from being saved.

Changes

File: src/admin/blueprints/products.py

  • Moved GAM config logic outside the line_item_type check
  • Now checks if adapter_type == "google_ad_manager" instead
  • Preserves existing implementation_config by starting with a copy
  • Only regenerates default config when line_item_type is explicitly provided
  • Allows placement/ad unit updates without full config regeneration

File: templates/add_product_gam.html

  • Added defensive type checking for targeted_placement_ids (handles both string and array)
  • Added console logging for troubleshooting placement population issues

Testing

  • All unit tests pass (861 passed, 7 skipped)
  • All integration tests pass (32 passed)
  • All integration_v2 tests pass (28 passed)
  • Pre-commit hooks all pass (syntax, linting, type checking)

Manual Testing Steps

  1. Edit a GAM product with multiple placements
  2. Change the placement selection (select different ones)
  3. Save the form
  4. Reload the edit page
  5. Verify the new placements are displayed ✅

Impact

  • Placements now save correctly when editing GAM products
  • Ad units now save correctly
  • Custom targeting now saves correctly
  • All GAM configuration updates are preserved
  • Works in both automatic and explicit line item type modes

Root cause: The GAM configuration save logic was nested inside an
'if line_item_type:' check. Since the form doesn't include line_item_type
(it's automatic now), this entire block never executed, causing placements
and other GAM config to not be saved.

Changes:
- Move GAM config save logic outside the line_item_type check
- Check 'if adapter_type == "google_ad_manager"' instead
- Preserve existing implementation_config by copying it first
- Only regenerate default config when line_item_type is present
- This allows placement/ad unit updates without full config regeneration

Now placements, ad units, targeting, and other GAM config will save
correctly even in automatic mode (no line_item_type field).
- Log product object and implementation config on page load
- Log placement IDs type and value
- Handle both string and array formats for targeted_placement_ids
- Add logging when setting hidden field value
- Log final populated placement IDs array

This will help diagnose placement persistence issues in the future.
@bokelley bokelley force-pushed the fix-placement-save-bug branch from 3d2ab3a to 83c6ad5 Compare November 4, 2025 10:44
@bokelley bokelley merged commit eb66e33 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
…contextprotocol#691)

* fix: GAM product edit not saving placements when line_item_type absent

Root cause: The GAM configuration save logic was nested inside an
'if line_item_type:' check. Since the form doesn't include line_item_type
(it's automatic now), this entire block never executed, causing placements
and other GAM config to not be saved.

Changes:
- Move GAM config save logic outside the line_item_type check
- Check 'if adapter_type == "google_ad_manager"' instead
- Preserve existing implementation_config by copying it first
- Only regenerate default config when line_item_type is present
- This allows placement/ad unit updates without full config regeneration

Now placements, ad units, targeting, and other GAM config will save
correctly even in automatic mode (no line_item_type field).

* chore: add diagnostic logging for placement field population

- Log product object and implementation config on page load
- Log placement IDs type and value
- Handle both string and array formats for targeted_placement_ids
- Add logging when setting hidden field value
- Log final populated placement IDs array

This will help diagnose placement persistence issues in the future.
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