Skip to content

fix(php): do not throw deprecated warning on field getters for default values #21033

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

Merged
merged 2 commits into from
Apr 21, 2025

Conversation

bshaffer
Copy link
Contributor

@bshaffer bshaffer commented Apr 1, 2025

backports the fix in #17788 for the 25.x branch, fixes #13428 in 25.x branch

@bshaffer bshaffer requested a review from a team as a code owner April 1, 2025 17:52
@bshaffer bshaffer requested review from ericsalo and removed request for a team April 1, 2025 17:52
@bshaffer bshaffer changed the title fix(php): do not throw deprecated warning on field getters for defaul… fix(php): do not throw deprecated warning on field getters for default values Apr 1, 2025
@bshaffer bshaffer added the 🅰️ safe for tests Mark a commit as safe to run presubmits over label Apr 1, 2025
@github-actions github-actions bot removed the 🅰️ safe for tests Mark a commit as safe to run presubmits over label Apr 1, 2025
@ericsalo ericsalo removed their request for review April 1, 2025 17:53
@anandolee
Copy link
Contributor

Hi Brent, from April 7 we will drop 25 support for everything except Java

@bshaffer
Copy link
Contributor Author

bshaffer commented Apr 4, 2025

@anandolee When you say "drop", do you mean "release"? And if so can we really try to get this merged before then?

@bshaffer bshaffer added the 🅰️ safe for tests Mark a commit as safe to run presubmits over label Apr 4, 2025
@github-actions github-actions bot removed the 🅰️ safe for tests Mark a commit as safe to run presubmits over label Apr 4, 2025
@rosmo
Copy link

rosmo commented Apr 7, 2025

@anandolee My customer would very much appreciate this being merged.

@bshaffer
Copy link
Contributor Author

bshaffer commented Apr 7, 2025

Expanding on this to say that because the googleapi public protos are on protobuf 25, all the client libraries generate messages using that protobuf version. We are trying to update it, but it's difficult since we need to do it for ALL languages at once, and there are some breaking change concerns with some languages for upgrading to 26.

This is a simple fix which is backported to 25 so we can resolve the issue for our customers now, instead of having to wait to upgrade protobuf for all the client libraries (which may be soon, and it may not be).

@protocolbuffers protocolbuffers deleted a comment from bshaffer Apr 7, 2025
@anandolee
Copy link
Contributor

Brent, we will discuss about the release tomorrow.

+Mike for PHP review

@@ -239,6 +239,20 @@ std::string DefaultForField(const FieldDescriptor* field) {
}
}

std::string DeprecatedConditionalForField(const FieldDescriptor* field) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current behavior of throwing seems obviously bad, but I don't think it makes sense to care if the field is a default value or not in protobuf semantics; is this actually an idiomatic PHP shape of behavior?

I would have expected the WAI behavior to just log an error on deprecated fields that are either get or set, and to not care about the default value and to never throw?

In general, if you have an implicit presence bool and read it and it has false, you're still using a deprecated path that should be moved off (if its deprecated then callers may stop setting it and it incorrectly has value false when it should have been true, logic reading it is wrong).

Copy link
Contributor Author

@bshaffer bshaffer Apr 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is that this check is performed internally. This is why customers get deprecated warnings in their logs even though they have not used the field. For this reason, we use checking in this way to say "if this field has been modified by the user, issue the deprecation warning"

The only other option would be to remove the deprecation warning entirely. This is fine with me, but we've already released the fix in this PR in the main branch of protobuf, so I'd rather keep it as-is unless there's a real concern with this implementation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@esrauchg Do you still have any addl concerns here for this backport, or is this good to approve + release?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think its suboptimal that explicit calls to read fields from the application code won't log if the value is the default value ("deprecated" could also mean "things may stop setting this even though the field is still there, if you read it and get the default value it might be right or might be bogus").

But I don't think we need to hold up the backport here; "deprecation messages when the application isn't doing anything" is more bad than "incorrectly not having coverage of getters that happen to be default" is bad.

@zhangskz zhangskz added php back-port Cherrypick PRs to release branches 🅰️ safe for tests Mark a commit as safe to run presubmits over labels Apr 18, 2025
@github-actions github-actions bot removed the 🅰️ safe for tests Mark a commit as safe to run presubmits over label Apr 21, 2025
@zhangskz zhangskz merged commit a4dc75f into protocolbuffers:25.x Apr 21, 2025
283 of 287 checks passed
@bshaffer
Copy link
Contributor Author

Thank you @zhangskz !

@bshaffer bshaffer deleted the backport-php-deprecation-fix branch April 21, 2025 17:24
@TomBrouws
Copy link

Hey @bshaffer ! Is there a timeline to update the googleapi public protos to use v25.7? Thanks for the effort thus far 🙏

@bshaffer
Copy link
Contributor Author

@TomBrouws Hey Tom! We are currently blocked because Java can't upgrade to v25.7 as it could be a breaking change for them... I wish it wasn't as complicated as it has been, but unfortunately it is. We are still looking for ways to make it happen, but there's no ETA yet.

@bshaffer
Copy link
Contributor Author

I spoke too soon - it's looking promising for us to make this change. I'll keep this bug updated on our progress!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
back-port Cherrypick PRs to release branches php
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants