-
Notifications
You must be signed in to change notification settings - Fork 15.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PHP] Adding a new enum value results in a breaking change? #16857
Comments
I believe the problem is that the user hasn't updated their library to receive the new enums. This is a problem we have seen happen when APIs add an enum value - the value can be sent before the client library of the user is updated to understand the new value. When that happens, errors like this can arise. The way to fix this error in the short term is for the user to update to the latest version of the client library. The way to prevent this in the long term is to surround each call to |
Protobuf libs are supposed to be tolerant to this and treat new values as |
@fiboknacky that's correct - protobuf and the client libraries are tolerant when they receive unknown enum values, but try {
$name = CriterionType::name($value); // throws exception when new values are added
} catch (UnexpectedValueException $e) {
// If the value is unknown, set values to some enum default (in this case, "UNKNOWN")
$name = 'UNKNOWN';
$value = 1;
} It would be possible in Protobuf to have |
I think it should return |
I think there's a misunderstanding. There is no breaking change, the methods We can't return We could have done something like return |
I may misunderstood the spec (some are defaults to Ads protos only), but let's get back to a basic question (putting the |
for PHP enums are OPEN. The unknown value is saved in the protobuf field even if it's unknown. There is no breaking change for new enums. |
Thanks. That reminds me that PHP doesn't have a real support for enum (at least for the currently supported PHP versions that we use), so it can be open like you said. The generated enum classes are just a convenient class representing the proto enums.
That's what I meant to ask about "breaking change" in this comment. Sorry that my misunderstanding made it more confusing by mentioning things about releasing new versions of protobuf. Let's say if we want to make a change for It's not a high priority now, but I wish to understand the situation first, so we can prioritize it in the future. Thanks! |
One way this could potentially be done in GAPIC is to overwrite/modify the generated protobuf classes. This is generally frowned upon, however. What changes would you want to make? |
I see. Personally, I think
For Ads, this would be much more predictable, since we have an Ads extended spec to always have two first values as |
@fiboknacky just a reminder that this library doesn't go against any spec because protobuf is agnostic of any API. It does not follow AIPs (which are specific to Google API standards). It can't return the value As for overwriting/modifying, again that would happen outside this library, so I can't really speak to that. If you want to write up a design or file a big against https://github.com/googleapis/gapic-generator-php, we can discuss it there. I think for now we can close this issue here. Do you agree? |
I didn't know that it doesn't follow AIPs. Thanks for the information.
Yes, I think this is more complicated than I thought and it's probably not about the protobuf spec itself. We should close this for now. Thanks. |
What version of protobuf and what language are you using?
Version: 3.x
Language: PHP
What operating system (Linux, Windows, ...) and version?
Probably all OS. I tested on Linux
What did you do?
After releasing a new version of the Google Ads API (v16_1), the Google Ads API PHP library is updated to accommodate this change.
In the release, we added one more new enum value to
CriterionType
.But when a user uses that enum class to parse a new value (
LIFE_EVENT
), it failed withEnum Google\Ads\GoogleAds\V16\Enums\CriterionTypeEnum\CriterionType has no name defined for value 41
What did you expect to see
Based on this doc , it should just parses the value without any issues.
I'd expect it to represent a new value with
UNKNOWN
and all methods in that enum class should just work.What did you see instead?
it failed with
Enum Google\Ads\GoogleAds\V16\Enums\CriterionTypeEnum\CriterionType has no name defined for value 41
when callingname()
.The text was updated successfully, but these errors were encountered: