"TypeError: Parameter to MergeFrom() must be instance of same class" during campaign mutate

2,259 views
Skip to first unread message

Bob Rzadzki

unread,
Oct 26, 2021, 8:40:22 PM10/26/21
to AdWords API and Google Ads API Forum
The code below loops over a list `response` containing tuples where the first element (`c[0]` in the snippet) is a campaign ID:

for c in response:
   campaign_operation = client.get_type('CampaignOperation')
   operation = campaign_operation.update
   operation.resource_name = campaign_service.campaign_path(google_id, c[0])
   operation.status = client.enums.CampaignStatusEnum.PAUSED
   client.copy_from(campaign_operation.update_mask, protobuf_helpers.field_mask(None, operation._pb))
   operations.append(operation)

campaign_response = campaign_service.mutate_campaigns(customer_id=google_id, operations=operations)

The last line throws the following exception:

Traceback (most recent call last):
  File "F:/.../campaign_pauser.py", line 162, in <module>
    campaign_response = campaign_service.mutate_campaigns(customer_id=google_id, operations=operations)
  File "F:\...\venv\lib\site-packages\google\ads\googleads\v8\services\services\campaign_service\client.py", line 610, in mutate_campaigns
    request.operations = operations
  File "F:\...\venv\lib\site-packages\proto\message.py", line 641, in __setattr__
    self._pb.MergeFrom(self._meta.pb(**{key: pb_value}))
TypeError: Parameter to MergeFrom() must be instance of same class: expected google.ads.googleads.v8.services.CampaignOperation got Campaign.

The code I'm using is essentially from the documentation here:


Cannot understand why there's a type mismatch happening. Any help appreciated.

Google Ads API Forum Advisor

unread,
Oct 27, 2021, 1:04:52 PM10/27/21
to robert...@gmail.com, adwor...@googlegroups.com
Hi Bob,

This support chanel handles API communications, for help with the Ads API Python client library you can go to their issue tracker.

With that being said, if you are using version 14 of the library there's some extra configuration necessary regarding Protobuf Messages.

Regards,

Google Logo
Aryeh Baker
Google Ads API Team
 


ref:_00D1U1174p._5004Q2QFXHg:ref

Bob Rzadzki

unread,
Oct 28, 2021, 10:30:01 AM10/28/21
to AdWords API and Google Ads API Forum
Thanks for pointing me in the right direction!
Reply all
Reply to author
Forward
0 new messages