googleads / google-ads-java

Google Ads API Client Library for Java
Apache License 2.0
170 stars 177 forks source link

FieldMasks Utility Does Not Properly Detect Campaign BiddingStrategy of MANUAL_CPC and EnhancedCpcEnabled = false #344

Closed PeterLavetsky closed 4 years ago

PeterLavetsky commented 4 years ago

Hi All,

This bug may partially be related to https://github.com/googleads/google-ads-java/issues/272

Setting the ManualCpc object on a Campaign with enhancedCpcEnabled = false, the FieldMask utility does not add the manual_cpc.enhanced_cpc_enabled path to the update_mask, and the change does not take effect on the mutate.

When enhancedCpcEnabled = true the FieldMask utility does add manual_cpc.enhanced_cpc_enabled to the update_mask and the intended change does take effect.

final ManualCpc manualCpc = ManualCpc.newBuilder()
                .setEnhancedCpcEnabled( false )
                .build();

googleCampaign.setManualCpc( manualCpc );

final FieldMask.Builder fieldMaskBuilder = FieldMasks.allSetFieldsOf( googleCampaign ).toBuilder();

operationBuilder
                    .setUpdate( googleCampaign )
                    .setUpdateMask( fieldMaskBuilder.build() );

Our current workaround:

if( fieldMaskBuilder.getPathsList().contains( "bidding_strategy_type" ) ) {
                    if( googleCampaign.hasManualCpc() && !fieldMaskBuilder.getPathsList().contains( "manual_cpc.enhanced_cpc_enabled" ) ) {
                        fieldMaskBuilder.addPaths( "manual_cpc.enhanced_cpc_enabled" );
                    }
                }

Does Not Work Request-id : zbMkzQ8qndiYjz6cVa2SHg Works Request-id : A6epI0FMrpTS2kOu6a2wKw

The full requests are shown below, but here are the diffs of two identical requests of the same campaign with the only difference being the enhanced_cpc_enabled flag is either true or false:

peterlavetsky@Harpua ~ $ diff works.txt does-not-work.txt 
0a1
> 
31c32
<       enhanced_cpc_enabled: true
---
>       enhanced_cpc_enabled: false
52d52
<     paths: "manual_cpc.enhanced_cpc_enabled"
peterlavetsky@Harpua ~ $ 

Relevant requests with IDs mostly obfuscated below. Can be provided if needed tho I believe the above request-ids should be enough.

Does not work:


Request
-------
MethodName: google.ads.googleads.v5.services.CampaignService/MutateCampaigns
Endpoint: googleads.googleapis.com:443
Headers: {developer-token=REDACTED, login-customer-id=084, x-goog-api-client=gl-java/1.8.0_161 gapic/ gax/1.57.0 grpc/1.30.0}
Body: customer_id: "052"
operations {
  update {
    resource_name: "customers/052/campaigns/481"
    status: ENABLED
    bidding_strategy_type: MANUAL_CPC
    manual_cpc {
      enhanced_cpc_enabled: false
    }  
  }
  update_mask {
    paths: "resource_name"
    paths: "status"
    paths: "bidding_strategy_type"
  }
}
partial_failure: true

Response
--------
Headers: Metadata(content-disposition=attachment,content-type=application/grpc,request-id=zbMkzQ8qndiYjz6cVa2SHg,date=Tue, 22 Sep 2020 22:50:40 GMT,alt-svc=h3-Q050=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-27=":443"; ma=2592000,h3-T051=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43")
Body: results {
  resource_name: "customers/052/campaigns/481"
}

Failure message: null
Status: Status{code=OK, description=null, cause=null}.
2020-09-22 18:51:36,221 DEBUG RequestLogger - SUCCESS REQUEST DETAIL.

Works:

Request
-------
MethodName: google.ads.googleads.v5.services.CampaignService/MutateCampaigns
Endpoint: googleads.googleapis.com:443
Headers: {developer-token=REDACTED, login-customer-id=084, x-goog-api-client=gl-java/1.8.0_161 gapic/ gax/1.57.0 grpc/1.30.0}
Body: customer_id: "052"
operations {
  update {
    resource_name: "customers/052/campaigns/481"
    status: ENABLED
    bidding_strategy_type: MANUAL_CPC
    manual_cpc {
      enhanced_cpc_enabled: true
    }  
  }
  update_mask {
    paths: "resource_name"
    paths: "status"
    paths: "bidding_strategy_type"
    paths: "manual_cpc.enhanced_cpc_enabled"
  }
}
partial_failure: true

Response
--------
Headers: Metadata(content-disposition=attachment,content-type=application/grpc,request-id=A6epI0FMrpTS2kOu6a2wKw,date=Tue, 22 Sep 2020 23:18:39 GMT,alt-svc=h3-Q050=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-27=":443"; ma=2592000,h3-T051=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43")
Body: results {
  resource_name: "customers/052/campaigns/481"
}

Failure message: null
Status: Status{code=OK, description=null, cause=null}.
2020-09-22 19:19:35,567 DEBUG RequestLogger - SUCCESS REQUEST DETAIL.

Thanks Pete

Java Client Library com.google.api-ads:google-ads:9.0.0

nwbirnie commented 4 years ago

Now fixed in master. Will be in the next release.