fix: remove float_precision for protobuf 7#559
Conversation
There was a problem hiding this comment.
Code Review
This pull request correctly addresses the removal of the float_precision argument in Protobuf 7. The approach of ignoring the argument and issuing a DeprecationWarning for newer versions is sound. The refactoring of to_json and to_dict into a shared helper function is a good improvement for code maintainability. I have one minor suggestion to simplify the logic for extracting the Protobuf major version.
|
@daniel-sanche , Please could you address the failing tests? |
|
|
||
| # TODO: https://github.com/googleapis/proto-plus-python/issues/390 | ||
| def test_json_float_precision(): | ||
| if int(proto.message._PROTOBUF_MAJOR_VERSION) >= 7: |
There was a problem hiding this comment.
NO ACTION:
I situations like this, I often choose to decorate a test with @pytest.mark.parametrize() and include one or more happy paths and sad paths (labeled with IDs for clarity when looking at the pytest results) rather than writing two separate tests. Avoids a lot of duplicate code. Not saying you need to do anything here. Just pointing it out as an option for future tests down the road.
There was a problem hiding this comment.
Good point. I think they started out different, but the code is pretty similar now. I'll take another look
There was a problem hiding this comment.
One downside of this approach is that we will no longer see new user warnings. For example, in October 2025, https://pypi.org/project/protobuf/6.33.0/ included a new deprecation warning for the float_precision argument, within the same major version. See the release notes for https://github.com/protocolbuffers/protobuf/releases/tag/v33.0-rc1
Can we use warnings.filterwarnings to narrow down the warnings that are filtered to the one that includes the text float_precision?
warnings.filterwarnings("ignore", message=".*float_precision.*")
There was a problem hiding this comment.
good point, fixed
Co-authored-by: Chalmer Lowe <chalmerlowe@google.com>
Co-authored-by: Anthonios Partheniou <partheniou@google.com>
PR created by the Librarian CLI to initialize a release. Merging this PR will auto trigger a release. Librarian Version: v1.0.1 Language Image: us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/python-librarian-generator@sha256:d7caef319a25d618e20ba798b103434700bfd80015f525802d87621ca2528c90 <details><summary>proto-plus: 1.27.1</summary> ## [1.27.1](v1.27.0...v1.27.1) (2026-01-30) ### Bug Fixes * remove float_precision for protobuf 7 (#559) ([390b9d5](390b9d57)) </details>

Fixes googleapis/google-cloud-python#15099
Protobuf 7 is removing the float_prevision argument. This PR ignores it when passed in 7.x+, and raises a DeprecationWarning