Skip to content

Commit c21679d

Browse files
authored
Fix arcane mypy errors (#189)
1 parent 765e05b commit c21679d

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

src/neptune_query/internal/retrieval/metric_buckets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from ..query_metadata_context import with_neptune_client_metadata
4040
from . import retry
4141
from .search import ContainerType
42-
from .util import ProtobufPayload
42+
from .util import body_from_protobuf
4343

4444
logger = get_logger()
4545

@@ -151,7 +151,7 @@ def fetch_time_series_buckets(
151151
call_api = retry.handle_errors_default(with_neptune_client_metadata(get_timeseries_buckets_proto.sync_detailed))
152152
response = call_api(
153153
client=client,
154-
body=ProtobufPayload(request_object),
154+
body=body_from_protobuf(request_object),
155155
)
156156

157157
logger.debug(

src/neptune_query/internal/retrieval/metrics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
logger = get_logger()
3939

4040
# Tuples are used here to enhance performance
41-
FloatPointValue = tuple[float, float, float, bool, float]
41+
FloatPointValue = tuple[int, float, float, bool, float]
4242
(
4343
TimestampIndex,
4444
StepIndex,

src/neptune_query/internal/retrieval/util.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,19 @@ def fetch_pages(
5656
page_params = make_new_page_params(page_params, data)
5757

5858

59-
class ProtobufPayload(File):
60-
"""A version of the neptune_api.types.File class that uses a protobuf message as payload"""
59+
class ReusableFile(File):
60+
"""A File that recreates its payload on each access to support retries."""
6161

6262
@property
6363
def payload(self) -> BinaryIO:
6464
return self.get_payload()
6565

6666
@payload.setter
67-
def payload(self, message: Message) -> None:
68-
self.get_payload = lambda: BytesIO(message.SerializeToString())
67+
def payload(self, payload: BinaryIO) -> None:
68+
stored_payload = payload.read()
69+
self.get_payload = lambda: BytesIO(stored_payload)
70+
71+
72+
def body_from_protobuf(message: Message) -> ReusableFile:
73+
"""Generate a ReusableFile from a protobuf message."""
74+
return ReusableFile(payload=BytesIO(message.SerializeToString()))

tests/unit/internal/retrieval/test_protobuf_payload.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
)
1010
from neptune_api.types import File
1111

12-
from neptune_query.internal.retrieval.util import ProtobufPayload
12+
from neptune_query.internal.retrieval.util import body_from_protobuf
1313

1414

1515
@mock.patch("neptune_query.internal.retrieval.util.BytesIO", wraps=BytesIO)
1616
def test_bytesio_recreation_on_retry(mock_bytesio):
1717
"""Test that BytesIO instance is recreated when the API call is retried."""
1818

19-
file = ProtobufPayload(
19+
file = body_from_protobuf(
2020
ProtoGetTimeseriesBucketsRequest(
2121
expressions=[ProtoCustomExpression(requestId="0123", customYFormula="${abc}")],
2222
view=ProtoView(xScale=ProtoScale.linear),
@@ -35,5 +35,6 @@ def test_bytesio_recreation_on_retry(mock_bytesio):
3535
assert read1 == read2
3636
assert read2 != b""
3737

38-
# Verify BytesIO was called twice
39-
assert mock_bytesio.call_count == 2
38+
# Verify BytesIO was called three times:
39+
# Once during ProtobufPayload creation and twice for the two reads
40+
assert mock_bytesio.call_count == 3

0 commit comments

Comments
 (0)