googleads / google-ads-php

Google Ads API Client Library for PHP
https://developers.google.com/google-ads/api/docs/client-libs/php
Apache License 2.0
284 stars 260 forks source link

FieldMasks::getFieldValue fails for enums #1037

Open mrpavlikov opened 1 month ago

mrpavlikov commented 1 month ago

Your client library and Google Ads API versions:

Your environment:

Description of the bug:

I've been retrieving account change history like example suggests: https://developers.google.com/google-ads/api/samples/get-change-details#php

Getting following error:

Call to a member function getName() on null {"exception":"[object] (Error(code: 0): Call to a member function getName() on null at /www/vendor/googleads/google-ads-php/src/Google/Ads/GoogleAds/Util/FieldMasks.php:307

I have change event in path geo_target_type_setting.positive_geo_target_type and new value is 7. Code that gives error FieldMasks.php:307 uses getValueDescriptorByIndex($index), but 7 is not the index, it is number. Your enum has "holes" and number does not match index, see PositiveGeoTargetType.

The only workaround I can think of is modifying my instance of lib for now, so it does this:

$property = new \ReflectionProperty(get_class($fieldDescriptor->getEnumType()), 'internal_desc');
$property->setAccessible(true);
$fieldValue = $property->getValue($fieldDescriptor->getEnumType())->getValueByNumber($fieldValue)->getName();

Expected behavior:

Returns PRESENCE

fiboknacky commented 1 month ago

Could you please post on the Google Ads API forum and refer to this issue? Please tell the agent on the forum that you want to privately share information with the PHP client library owner. They'll guide you how to Reply privately to them. Share your customer ID there, so I can try reproducing this issue. Thanks!