Skip to content

Commit a6a2a81

Browse files
Jwredentkathole
authored andcommitted
test: add regression tests for protobuf >= 7.34.0 compatibility (#6435)
PR #6015 replaced MessageToDict with a custom dict builder in feature_server.py, which incidentally fixed the crash caused by the removed float_precision kwarg in protobuf >= 7.34.0. Add explicit regression tests to prevent reintroduction: - Verify convert_response_to_dict never calls MessageToDict - Verify double precision round-trips without float_precision kwarg Fixes #6435 Assisted-by: Claude Opus 4.6 Signed-off-by: Jonathan Wrede <wrede.jonathan00@gmail.com>
1 parent bac790e commit a6a2a81

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

sdk/python/tests/unit/test_feature_server_utils.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,60 @@ def test_complex_types_are_json_serializable(self):
551551
assert serialized # non-empty
552552

553553

554+
class TestProtobufCompatibility:
555+
"""Regression tests for protobuf >= 7.34.0 compatibility (issue #6435).
556+
557+
protobuf 7.34.0 removed the float_precision kwarg from MessageToDict.
558+
convert_response_to_dict must never call MessageToDict, so it is immune
559+
to this breaking change regardless of the installed protobuf version.
560+
"""
561+
562+
def test_no_message_to_dict_dependency(self):
563+
"""convert_response_to_dict must not call MessageToDict internally."""
564+
import unittest.mock as mock
565+
566+
response = GetOnlineFeaturesResponse()
567+
fv = response.results.add()
568+
fv.values.append(Value(double_val=3.141592653589793))
569+
fv.values.append(Value(int64_val=42))
570+
fv.values.append(Value(string_val="hello"))
571+
fv.statuses.extend(
572+
[FieldStatus.PRESENT, FieldStatus.PRESENT, FieldStatus.PRESENT]
573+
)
574+
response.metadata.feature_names.val.extend(["f1", "f2", "f3"])
575+
576+
with mock.patch(
577+
"google.protobuf.json_format.MessageToDict",
578+
side_effect=AssertionError("MessageToDict must not be called"),
579+
):
580+
result = convert_response_to_dict(response)
581+
582+
assert len(result["results"]) == 1
583+
assert result["results"][0]["values"] == [3.141592653589793, 42, "hello"]
584+
assert result["metadata"]["feature_names"] == ["f1", "f2", "f3"]
585+
586+
def test_double_precision_without_float_precision_kwarg(self):
587+
"""Doubles must round-trip without the removed float_precision kwarg."""
588+
values = [
589+
1e-300,
590+
1.7976931348623157e308,
591+
2.2250738585072014e-308,
592+
0.1 + 0.2,
593+
]
594+
response = GetOnlineFeaturesResponse()
595+
fv = response.results.add()
596+
for v in values:
597+
fv.values.append(Value(double_val=v))
598+
fv.statuses.append(FieldStatus.PRESENT)
599+
600+
result = convert_response_to_dict(response)
601+
for i, expected in enumerate(values):
602+
actual = result["results"][0]["values"][i]
603+
assert actual == expected, f"Mismatch at index {i}: {actual} != {expected}"
604+
round_tripped = json.loads(json.dumps(actual))
605+
assert round_tripped == expected
606+
607+
554608
class TestPerformance:
555609
"""Performance tests to validate the optimization claim."""
556610

0 commit comments

Comments
 (0)