Setting Empty Message Objects as Fields

In the Google Ads API some message fields are defined as empty message objects, for example campaign.manual_cpm. The value for this field is an instance of ManualCpm, which is an empty message object, meaning it has no fields of its own.

When creating a new campaign, for example, we normally set a field that is a Well Known Type by augmenting it directly, for example:

# is an instance of a Well Known Type, StringValue = 'Test campaign value'

However, since campaign.manual_cpm is not a Well Known Type and has no fields to augment, there is no clear way to set it on the campaign message object. In order to set the field we need to use the built-in CopyFrom method. This also requires us to initialize a new instance of the ManualCpm message class:


Note how manual_cpm is specified for the campaign object:

name {
  value: "Test campaign value"
manual_cpm {

For more specific details about the behavior of generated protobuf objects in Python review the Python Generated Code documentation.