Bug:
Approving a media buy with a GAM product that has custom_targeting_keys in the "groups" format fails with:
Order created but failed to create line items: 'groups'
Root cause:
In src/adapters/gam/managers/orders.py (lines 467-473), product-level custom_targeting_keys from implementation_config are merged raw into the GAM line item's customTargeting dict by iterating over the dict keys. When the targeting uses the "groups" format ({"groups": [{"criteria": [...]}]}), the key "groups" is inserted directly into what should be a GAM CustomCriteriaSet structure (which expects xsi_type, logicalOperator, children). When zeep serializes this to the GAM SOAP API, it encounters the unknown "groups" field and raises KeyError('groups').
The targeting manager (src/adapters/gam/managers/targeting.py) already has _build_custom_targeting_structure() which correctly handles all three custom targeting formats (legacy, enhanced, groups) and produces valid GAM structures - but it was not being used for product-level custom targeting in the line item creation path.
Proposed Fix:
Route product custom_targeting_keys through targeting_manager._build_custom_targeting_structure() before merging with buyer targeting. When both buyer and product targeting exist, combine them under an AND CustomCriteriaSet. Pass the targeting manager from google_ad_manager.py into create_line_items().
Files changed:
src/adapters/gam/managers/orders.py — replace raw dict merge with proper targeting manager processing
src/adapters/google_ad_manager.py — pass targeting_manager to create_line_items()
Bug:
Approving a media buy with a GAM product that has
custom_targeting_keysin the "groups" format fails with:Root cause:
In
src/adapters/gam/managers/orders.py(lines 467-473), product-levelcustom_targeting_keysfromimplementation_configare merged raw into the GAM line item'scustomTargetingdict by iterating over the dict keys. When the targeting uses the "groups" format ({"groups": [{"criteria": [...]}]}), the key"groups"is inserted directly into what should be a GAMCustomCriteriaSetstructure (which expectsxsi_type,logicalOperator,children). When zeep serializes this to the GAM SOAP API, it encounters the unknown"groups"field and raisesKeyError('groups').The targeting manager (
src/adapters/gam/managers/targeting.py) already has_build_custom_targeting_structure()which correctly handles all three custom targeting formats (legacy, enhanced, groups) and produces valid GAM structures - but it was not being used for product-level custom targeting in the line item creation path.Proposed Fix:
Route product
custom_targeting_keysthroughtargeting_manager._build_custom_targeting_structure()before merging with buyer targeting. When both buyer and product targeting exist, combine them under an ANDCustomCriteriaSet. Pass the targeting manager fromgoogle_ad_manager.pyintocreate_line_items().Files changed:
src/adapters/gam/managers/orders.py— replace raw dict merge with proper targeting manager processingsrc/adapters/google_ad_manager.py— passtargeting_managertocreate_line_items()