Skip to content

Commit

Permalink
fix(framework) Fix the bug in HasField method (#4376)
Browse files Browse the repository at this point in the history
  • Loading branch information
panh99 authored Oct 28, 2024
1 parent a98f069 commit 95443d5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/py/flwr/server/superlink/driver/driver_servicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from uuid import UUID

import grpc
from google.protobuf.message import Message as GrpcMessage

from flwr.common.constant import Status
from flwr.common.logger import log
Expand Down Expand Up @@ -212,7 +213,7 @@ def PullServerAppInputs(
# Lock access to LinkState, preventing obtaining the same pending run_id
with self.lock:
# If run_id is provided, use it, otherwise use the pending run_id
if request.HasField("run_id"):
if _has_field(request, "run_id"):
run_id: Optional[int] = request.run_id
else:
run_id = state.get_pending_run_id()
Expand Down Expand Up @@ -256,3 +257,8 @@ def PushServerAppOutputs(
def _raise_if(validation_error: bool, detail: str) -> None:
if validation_error:
raise ValueError(f"Malformed PushTaskInsRequest: {detail}")


def _has_field(message: GrpcMessage, field_name: str) -> bool:
"""Check if a certain field is set for the message, including scalar fields."""
return field_name in {fld.name for fld, _ in message.ListFields()}

0 comments on commit 95443d5

Please sign in to comment.