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

getLabel is deprecated. Use isRequired or isRepeated instead.

Open urbanovich opened this issue 8 months ago • 13 comments

Hello,

I have bug with using last version of the library(v26.2):

{"exception":"[object] (ErrorException(code: 0): getLabel is deprecated. Use isRequired or isRepeated instead.
at /app/vendor/googleads/google-ads-php/src/Google/Ads/GoogleAds/Util/FieldMasks.php:356)

in code it's:

/**
     * @param FieldDescriptor $fieldDescriptor the field descriptor to check if it's repeated
     * @return bool true if the field descriptor is repeated
     */
    private static function isFieldRepeated(FieldDescriptor $fieldDescriptor)
    {
        return $fieldDescriptor->getLabel() === GPBLabel::REPEATED;
    }

urbanovich avatar May 16 '25 14:05 urbanovich

Thanks for submitting this: it will be fixed in the next release of the client library.

Raibaz avatar May 16 '25 14:05 Raibaz

@Raibaz

could you say when it will be?

urbanovich avatar May 16 '25 14:05 urbanovich

V20 of the Google Ads API will be released on June 6th, so we will be releasing a new version of the client library along with it.

Raibaz avatar May 18 '25 13:05 Raibaz

@Raibaz

Do you plan to release a fix for this issue anytime soon?

thanks!

urbanovich avatar Jun 11 '25 14:06 urbanovich

@Raibaz

Do you have any update on this? I just installed the latest version of the library but the fix seems to not be along with it. Im on api V18 could it be the problem?

Thank you!

jeffersoncechinel avatar Jun 11 '25 20:06 jeffersoncechinel

@Raibaz The issue still persists. It seems that simply updating the method in the Google\Ads\GoogleAds\Util\FieldMasks class would resolve the problem. It would be great if an update could be released soon to address this. Thanks in advance!

    /**
     * @param FieldDescriptor $fieldDescriptor the field descriptor to check if it's repeated
     * @return bool true if the field descriptor is repeated
     */
    private static function isFieldRepeated(FieldDescriptor $fieldDescriptor)
    {
        return $fieldDescriptor->isRepeated();
    }

cbringmann avatar Jun 12 '25 11:06 cbringmann

@cbringmann

I was going to propose the same fix/hack here but you just did. Thanks!

jeffersoncechinel avatar Jun 12 '25 13:06 jeffersoncechinel

@cbringmann

Hi!

I know the issue, you need to update google/protobuf - https://github.com/googleads/google-ads-php/blob/83134844b301e2ac15319b2c8dc0ede3bc31aa2f/composer.json#L9 to last version because isRepeated method is not available in these versions: ^3.21.5 || ^4.26

urbanovich avatar Jun 13 '25 07:06 urbanovich

maybe releated #1083

we still see UndefinedMethod: Method Google\Protobuf\Internal\RepeatedField::offsetGet does not exist on v28

ro0NL avatar Jun 19 '25 17:06 ro0NL

I'm taking a look at this, thank you all for your patience, I hope to have a fix pushed out by the end of next week.

Brothman avatar Jun 20 '25 13:06 Brothman

perhaps also add a psalm/phpstan CI job, to catch things early with low-high deps

ro0NL avatar Jun 27 '25 11:06 ro0NL

I updated the client library to use isRepeated in v29.0.0 (https://github.com/googleads/google-ads-php/releases/tag/v29.0.0)/.

This solved the issue for me on my local machine. Can you all confirm if this issue is resolved for you in this new version of the library?

Brothman avatar Jun 27 '25 21:06 Brothman

IIUC this issue and https://github.com/googleads/google-ads-php/issues/1083 is fixed.

ro0NL avatar Jun 28 '25 22:06 ro0NL

This issue (1084) should be fixed with the recent PHP client library release. I'm keeping this issue open for another week, just in case anyone is still running into issues, so they can post it here and I can investigate further.

As for #1083, I didn't explicitly address that with this release, so I will continue the conversation with you on that issue directly.

Brothman avatar Jun 30 '25 16:06 Brothman

@ro0NL @Brothman

I've tested new version v29.0, and see the new mistake: Call to undefined method Google\Protobuf\FieldDescriptor::isRepeated() i'm sure that need to update google/protobuf to latest version

urbanovich avatar Jul 01 '25 14:07 urbanovich

Thank you for calling that out, @urbanovich. Taking a closer look, I see the isRepeated() method was only just added in v31.0, i.e. 4.31.0.

I'll work to update the dependencies and update it in the next version of the client library (will keep this issue open until then).

Brothman avatar Jul 01 '25 20:07 Brothman

I am also facing same issue when trying to update audiencelist.

Call to undefined method Google\Protobuf\FieldDescriptor::isRepeated()

On Line Number: 356 Google/Ads/GoogleAds/Util/FieldMasks.php

chiragvels avatar Jul 09 '25 05:07 chiragvels

@chiragvels Until we get the next client library version out, can you update line 9 in composer.json to be: google/protobuf": "4.31.0",

Then run composer update to get the newest protobuf version installed that has the method Google\Protobuf\FieldDescriptor::isRepeated().

Please let us know if you run into any errors when making this change.

Brothman avatar Jul 09 '25 14:07 Brothman

I can see that under composer.lock I am already having google/protobuf (v4.31.1)

And I am still getting the error:

Type: Error Message: Call to undefined method Google\Protobuf\FieldDescriptor::isRepeated()

I did this change as a work around

From this line

$operation->setUpdateMask(FieldMasks::allSetFieldsOf($userList));

To

$fieldMask = new \Google\Protobuf\FieldMask();
        $fieldMask->setPaths(['description']);
        $operation->setUpdateMask($fieldMask);

Thanks,

chiragvels avatar Jul 11 '25 07:07 chiragvels

Thank you for pointing that out, and the workaround @chiragvels.

I create Issue 1092 stating that because of dependency complications with the v29.0.0 release, we're deprecating v29.0.0, and will be releasing v30.0.0 to fix those complications so we have a working client library out of the box, no workaround needed. Then later, once those dependency complications are fixed internally, we will release another client library version.

I'll post another update here when v30.0.0 is released.

Brothman avatar Jul 11 '25 19:07 Brothman

Hi, we released v30, in which we pinned the protobuf version to v4.30 to prevent this error. As such, we went back to the old getLabel method, which isn't deprecated in v4.30.

Please follow issue 1095 for updates on when we will resolve the underlying protobuf dependency conflict, at which time we will release a new client library, that uses v4.31 of protobuf onwards (alongside isRepeated).

Brothman avatar Jul 21 '25 15:07 Brothman