googleads / google-ads-python

Google Ads API Client Library for Python
Apache License 2.0
526 stars 480 forks source link

graphql.error.graphql_error.GraphQLError: Assignment not allowed to message, map, or repeated field "long_headline" in protocol message object. #805

Closed sidd-ideaclan closed 1 year ago

sidd-ideaclan commented 1 year ago

Hi, I am trying to create a Responsive Display Ad and getting this error while assigning value to the required field 'long_headline' -

graphql.error.graphql_error.GraphQLError: Assignment not allowed to message, map, or repeated field "long_headline" in protocol message object.

It is due to this line -

ad_group_ad.ad.responsive_display_ad.long_headline = create_ad_text_asset(client, ad['ad']['responsive_display_ad']['long_headline'])

I know that 'long_headline' field is not a list, this is why I used assignment. But I also tried using the below method-

ad_group_ad.ad.responsive_display_ad.long_headline.extend(create_ad_text_asset(client, ad['ad']['responsive_display_ad']['long_headline']))

and as expected, this error came-

graphql.error.graphql_error.GraphQLError: extend

What am I doing wrong?

BenRKarl commented 1 year ago

@sidd-ideaclan - thanks for the question. The reason the assignment is raising an error is that - I'm assuming - you have the use-proto-plus configuration set to False. Normal protobuf messages will only let you make assignments for scalar fields (i.e. strings, enums, numbers). So you have two options here:

  1. Keep use-proto-plus set to False and update the AdTextAsset on the AdGroupAd instead of creating it separately. I'm not sure what fields you're modifying, but it would look something like this:

    ad_group_ad.ad.responsive_display_ad.long_headline.text = "this is a long headline"
    ad_group_ad.ad.responsive_display_ad.long_headline.pinned_field = client.enums.AD_IMAGE
  2. Change use-proto-plus to True and you can make assignments to non-scalar fields.