chore: add deprecation warnings for grpcio - #17981
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces deprecation warnings across several Google Cloud Python packages and templates when grpcio < 1.83.0 is detected, preparing for the enforcement of Post-Quantum Cryptography (PQC) requirements in October 2026. The feedback highlights a critical bug in the version parsing logic used in google-auth, google-cloud-bigquery, and google-cloud-ndb. Specifically, the current implementation fails to parse pre-release versions (e.g., 1.83.1rc1) correctly, resulting in truncated version tuples (e.g., (1, 83)) that incorrectly trigger false-positive deprecation warnings. To resolve this, the reviewer suggested updated parsing logic that extracts only the leading digits of each version component.
| _grpc_parts = [] | ||
| for _p in _grpc_ver_str.split("."): | ||
| try: | ||
| _grpc_parts.append(int(_p)) | ||
| except ValueError: | ||
| break |
There was a problem hiding this comment.
The current version parsing logic breaks on any non-integer character (e.g., rc1 or dev0), which means a version like 1.83.1rc1 will be parsed as (1, 83). Since (1, 83) < (1, 83, 0) is True, this will trigger a false positive deprecation warning for users on newer pre-release versions of grpcio. Parsing only the leading digits of each version component correctly handles pre-releases and avoids false positives.
_grpc_parts = []
for _p in _grpc_ver_str.split("."):
_digits = ""
for _c in _p:
if not _c.isdigit():
break
_digits += _c
if _digits:
_grpc_parts.append(int(_digits))
else:
break| try: | ||
| from importlib import metadata | ||
|
|
||
| _grpc_ver_str = metadata.version("grpcio") | ||
| _grpc_parts = [] | ||
| for _p in _grpc_ver_str.split("."): | ||
| try: | ||
| _grpc_parts.append(int(_p)) | ||
| except ValueError: | ||
| break |
There was a problem hiding this comment.
The current version parsing logic breaks on any non-integer character (e.g., rc1 or dev0), which means a version like 1.83.1rc1 will be parsed as (1, 83). Since (1, 83) < (1, 83, 0) is True, this will trigger a false positive deprecation warning for users on newer pre-release versions of grpcio. Parsing only the leading digits of each version component correctly handles pre-releases and avoids false positives.
_grpc_parts = []
for _p in _grpc_ver_str.split("."):
_digits = ""
for _c in _p:
if not _c.isdigit():
break
_digits += _c
if _digits:
_grpc_parts.append(int(_digits))
else:
breakReferences
- Before flagging a potential NameError or suggesting a fully-qualified import path in a code review, verify all module-level imports to ensure the module or variable is not already imported.
| _grpc_parts = [] | ||
| for _p in _grpc_ver_str.split("."): | ||
| try: | ||
| _grpc_parts.append(int(_p)) | ||
| except ValueError: | ||
| break |
There was a problem hiding this comment.
The current version parsing logic breaks on any non-integer character (e.g., rc1 or dev0), which means a version like 1.83.1rc1 will be parsed as (1, 83). Since (1, 83) < (1, 83, 0) is True, this will trigger a false positive deprecation warning for users on newer pre-release versions of grpcio. Parsing only the leading digits of each version component correctly handles pre-releases and avoids false positives.
_grpc_parts = []
for _p in _grpc_ver_str.split("."):
_digits = ""
for _c in _p:
if not _c.isdigit():
break
_digits += _c
if _digits:
_grpc_parts.append(int(_digits))
else:
break
wip