google-ads-php icon indicating copy to clipboard operation
google-ads-php copied to clipboard

FieldMasks::getFieldValue fails for enums

Open mrpavlikov opened this issue 7 months ago • 1 comments

Your client library and Google Ads API versions:

  • Client library version: v22.1.0
  • Google Ads API version: V16

Your environment:

  • The PHP version: 8.0.30
  • The name and version of the operating system: Linux a59f316b98dd 6.8.0-38-generic #38-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 7 15:25:01 UTC 2024 x86_64
  • Whether the PHP Extension protobuf is used or not: No.
  • Whether the PHP Extension grpc is used or not: No.
  • The type of transport being used (grpc or rest): Rest

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

mrpavlikov avatar Jul 18 '24 14:07 mrpavlikov