Repository navigation
fix(python): soften grpc generated version check in proto stubs - #81
Sunny (sunnylovestiramisu) wants to merge 1 commit into
Conversation
Change raise RuntimeError to warnings.warn in env_pb2_grpc.py and guest_pb2_grpc.py to prevent hard crashes when importing in environments with slightly different grpcio versions.
Tomer Glottmann (tomergee)
left a comment
There was a problem hiding this comment.
Request changes. The PR edits generated files to hide a dependency conflict instead of fixing the conflict.
Blocking
-
clients/python/src/ate_env/_gen/ateenv/v1alpha/env_pb2_grpc.py:31andguest_pb2_grpc.py:31— these files are generated. The banner on line 15 saysDO NOT EDIT, andclients/python/scripts/gen-protos.shoverwrites them. The next proto change reverts this PR silently. A fix must live in the generator inputs or inpyproject.toml. -
Same lines — the check guards a real incompatibility. The stubs call
channel.unary_unary(..., _registered_method=True)in eight places inenv_pb2_grpc.py. A runtime older than the generator rejects that keyword. Withwarnings.warn,import ate_envsucceeds and the first RPC fails with aTypeErrorfar from the cause. TheRuntimeErrornames both versions and both remedies. Python shows aUserWarningonce, and many test runners filter it. -
clients/python/pyproject.toml:27— the package already requiresgrpcio>=1.83, above the generated1.81.1, andintegrations/nemo-gym/pyproject.toml:28requires the same. An environment that reaches this check installed grpcio below the package's own bound, and pip reports that as a conflict. The PR must name that environment and its grpcio version. The fix belongs there, or in this package's bound, not in the stubs.
Before merge, if an older runtime must be supported
-
Regenerate with a
grpcio-toolsthat matches the oldest runtime to support, and lowergrpcio>=inpyproject.tomlto that version.GRPC_GENERATED_VERSIONthen equals the bound and the check passes by construction. Rungen-protos.shwith that tool pinned, and add the license headers back, because the script does not write them. -
Rebase onto
main. The branch is one commit behind, and #70 regeneratedenv_pb2.py. This is also the same edit as cccfb08 on #75; drop it there once this PR decides the approach.
Nits
- The body states the problem as "slightly mismatched grpcio versions" but does not say which environment pins the old grpcio. Name it, because that decides between option 3 and option 4.
|
Should respect the grpcio>=1.83 dependency everywhere and revert the PR1 change. |
Summary
Softens the version compatibility check in generated gRPC Python stubs (
env_pb2_grpc.pyandguest_pb2_grpc.py) fromraise RuntimeError(...)towarnings.warn(...).This prevents catastrophic, unrecoverable crashes at
import ate_envin Python environments with slightly mismatchedgrpcioruntime versions.Background & Problem
In recent versions of
grpcio-tools, the protobuf compiler injects a version check header at the top of generated*_pb2_grpc.pyfiles: