Derive DisciplineServer from the servicer base class (#70) - #86
Merged
Conversation
DisciplineServer inherited disc.DisciplineService, the generated experimental static-call API, rather than DisciplineServiceServicer, which is what add_DisciplineServiceServicer_to_server is written against. Nothing broke in practice -- the registration helper looks handlers up by name and DisciplineServer defines all eight RPCs itself -- but the class did not inherit the UNIMPLEMENTED defaults a servicer base provides, so a subclass omitting an RPC would resolve to a static network-call stub instead of returning a clean UNIMPLEMENTED status. ExplicitServer and ImplicitServer already mixed in the correct servicers; this brings the base class in line.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #70.
DisciplineServerderived fromdisc.DisciplineService, which despite the nameis the generated experimental client-side API — a set of
@staticmethods thateach open a one-shot channel to a target address. The servicer base that
add_DisciplineServiceServicer_to_serveris written against isDisciplineServiceServicer.ExplicitServerandImplicitServeralready mixedin the correct servicers, so the inconsistency was confined to the base class.
Impact
No shipping code path reached the difference. The registration helper looks
handlers up by name rather than by type, and
DisciplineServeroverrides alleight RPCs itself, so the inherited staticmethods were always shadowed. This is
a latent-correctness fix, not a fix for an active bug.
What it protects is an RPC left undefined — realistically one added to the
.protoand regenerated but not yet implemented here. Note that the issuedescribes that case incorrectly: it claims an
AttributeErrorat registrationtime. Registration actually succeeds, because the static API supplies the
attribute. The failure lands at call time instead, and its shape depends on
whether anything in the process has imported
grpc.experimental:AttributeError: module 'grpc' has no attribute 'experimental'contextargument to its owntargetparameter and fails with
TypeError: Argument 'target' has incorrect type (expected bytes, got Mock)while trying to dial theServicerContextas anetwork address
Either way the handler raises without setting a status, so the client sees
UNKNOWNon a live request. After this change the servicer default setsUNIMPLEMENTEDand reports it properly.MRO
Both subclasses resolve cleanly:
ExplicitServer → DisciplineServer → DisciplineServiceServicer → ExplicitServiceServicer → objectImplicitServer → DisciplineServer → DisciplineServiceServicer → ImplicitServiceServicer → objectTests
Two regression tests in
tests/test_discipline_server.py: one asserts the baseclass directly, the other rebuilds
DisciplineServerwithout its ownGetInfoand checks the inherited method is the servicer's
UNIMPLEMENTEDdefault ratherthan the static client stub. Both were confirmed to fail against the old base and
pass against the new one, so they catch a revert.
Full suite: 335 passed.