|
21 | 21 | Related issue: https://github.com/feast-dev/feast/issues/6013 |
22 | 22 | """ |
23 | 23 |
|
| 24 | +import base64 |
24 | 25 | import json |
25 | 26 | import time |
26 | 27 |
|
@@ -104,7 +105,7 @@ def test_bytes_val(self): |
104 | 105 | data = b"\x00\x01\x02\x03" |
105 | 106 | v = Value(bytes_val=data) |
106 | 107 | result = _value_to_native(v) |
107 | | - assert result == data |
| 108 | + assert result == base64.b64encode(data).decode("ascii") |
108 | 109 |
|
109 | 110 | def test_double_list_val(self): |
110 | 111 | v = Value(double_list_val=DoubleList(val=[1.1, 2.2, 3.3])) |
@@ -144,7 +145,10 @@ def test_unix_timestamp_val(self): |
144 | 145 | def test_bytes_list_val(self): |
145 | 146 | v = Value(bytes_list_val=BytesList(val=[b"\x00\x01", b"\x02\x03"])) |
146 | 147 | result = _value_to_native(v) |
147 | | - assert result == [b"\x00\x01", b"\x02\x03"] |
| 148 | + assert result == [ |
| 149 | + base64.b64encode(b"\x00\x01").decode("ascii"), |
| 150 | + base64.b64encode(b"\x02\x03").decode("ascii"), |
| 151 | + ] |
148 | 152 |
|
149 | 153 | def test_unix_timestamp_list_val(self): |
150 | 154 | v = Value(unix_timestamp_list_val=Int64List(val=[1609459200, 1609545600])) |
@@ -458,7 +462,6 @@ def test_double_val_precision(self): |
458 | 462 | the only difference is how many trailing digits appear in the JSON string. |
459 | 463 | This is an intentional trade-off for speed and is safe for all ML feature values. |
460 | 464 | """ |
461 | | - import json |
462 | 465 | import struct |
463 | 466 |
|
464 | 467 | # Use a value with many significant digits |
@@ -496,20 +499,25 @@ def test_set_types_return_flat_list(self): |
496 | 499 | assert isinstance(values[0], list), "set type should be a flat list" |
497 | 500 | assert set(values[0]) == {"a", "b", "c"} |
498 | 501 |
|
499 | | - def test_bytes_values_match_patched_message_to_dict(self): |
500 | | - """Ensure bytes serialization matches proto_json.patch() format (raw bytes).""" |
| 502 | + def test_bytes_val_is_base64_encoded(self): |
| 503 | + """bytes_val is base64-encoded so JSONResponse can serialize it. |
| 504 | +
|
| 505 | + This intentionally differs from proto_json.patch() which returns raw bytes. |
| 506 | + Raw bytes are not JSON-serializable; base64 is the standard protobuf JSON |
| 507 | + encoding for bytes fields and is safe for all HTTP clients. |
| 508 | + """ |
501 | 509 | response = GetOnlineFeaturesResponse() |
502 | 510 | fv = response.results.add() |
503 | | - fv.values.append(Value(bytes_val=b"\x00\x01\x02\xff")) |
| 511 | + data = b"\x00\x01\x02\xff" |
| 512 | + fv.values.append(Value(bytes_val=data)) |
504 | 513 | fv.statuses.append(FieldStatus.PRESENT) |
505 | 514 |
|
506 | | - fast_result = convert_response_to_dict(response) |
507 | | - standard_result = MessageToDict(response, preserving_proto_field_name=True) |
| 515 | + result = convert_response_to_dict(response) |
| 516 | + encoded = result["results"][0]["values"][0] |
508 | 517 |
|
509 | | - assert ( |
510 | | - fast_result["results"][0]["values"] |
511 | | - == standard_result["results"][0]["values"] |
512 | | - ) |
| 518 | + assert encoded == base64.b64encode(data).decode("ascii") |
| 519 | + # Must be JSON-serializable |
| 520 | + assert json.dumps(encoded) |
513 | 521 |
|
514 | 522 |
|
515 | 523 | class TestJsonSerializability: |
|
0 commit comments