Skip to content

Commit a4d3b5f

Browse files
michalsosnMichał Sośnicki
andauthored
fix: MetadataSplitter no longer generates empty updates (#325)
Co-authored-by: Michał Sośnicki <[email protected]>
1 parent 986ade1 commit a4d3b5f

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

src/neptune_scale/sync/metadata_splitter.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,21 +116,18 @@ def __init__(
116116
self._file_series = peekable(self._stream_files(file_series)) if file_series else None
117117

118118
self._max_update_bytes_size = max_message_bytes_size
119-
self._has_returned = False
120119

121120
def __iter__(self) -> MetadataSplitter:
122-
self._has_returned = False
123121
return self
124122

125123
def __next__(self) -> UpdateRunSnapshot:
126124
if (
127-
self._has_returned
128-
and not self._configs
129-
and not self._metrics
130-
and not self._add_tags
131-
and not self._remove_tags
132-
and not self._files
133-
and not self._file_series
125+
not bool(self._configs)
126+
and not bool(self._metrics)
127+
and not bool(self._add_tags)
128+
and not bool(self._remove_tags)
129+
and not bool(self._files)
130+
and not bool(self._file_series)
134131
):
135132
raise StopIteration
136133

@@ -170,7 +167,6 @@ def __next__(self) -> UpdateRunSnapshot:
170167
size=size,
171168
)
172169

173-
self._has_returned = True
174170
return update
175171

176172
def populate_assign(

tests/unit/test_metadata_splitter.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,7 @@ def test_empty():
7777
result = list(builder)
7878

7979
# then
80-
assert len(result) == 1
81-
operation = result[0]
82-
expected_update = UpdateRunSnapshot(timestamp=Timestamp(seconds=1722341532, nanos=21934))
83-
assert operation == expected_update
80+
assert len(result) == 0
8481

8582

8683
@freeze_time("2024-07-30 12:12:12.000022")
@@ -437,25 +434,26 @@ def test_split_large_tags():
437434
]
438435

439436

440-
@pytest.mark.parametrize("action", ("raise", "drop"))
437+
@pytest.mark.parametrize("action", ["raise", "drop"])
441438
@pytest.mark.parametrize(
442439
"invalid_path",
443-
(None, "A" * 1025, UTF_CHAR * 256 + "A", object(), 1, 1.0, True, frozenset(), tuple(), datetime.now()),
440+
[None, "A" * 1025, UTF_CHAR * 256 + "A", object(), 1, 1.0, True, frozenset(), tuple(), datetime.now()],
444441
)
445-
@pytest.mark.parametrize("param_name", ("add_tags", "remove_tags", "configs", "metrics", "files", "file_series"))
442+
@pytest.mark.parametrize("param_name", ["add_tags", "remove_tags", "configs", "metrics", "files", "file_series"])
446443
def test_invalid_paths(caplog, action, invalid_path, param_name):
447-
data = {invalid_path: object()}
448444
step = None
449445
kwargs = {name: None for name in ("add_tags", "remove_tags", "configs", "metrics", "files", "file_series")}
450446

451447
if param_name == "metrics":
452-
data = Metrics(data=data)
448+
data = Metrics(data={invalid_path: 1})
453449
step = 1
454450
elif param_name == "files":
455451
data = {invalid_path: FileRefData(destination="x", mime_type="text/plain", size_bytes=0)}
456452
elif param_name == "file_series":
457453
data = {invalid_path: FileRefData(destination="x", mime_type="text/plain", size_bytes=0)}
458454
step = 1
455+
else:
456+
data = {invalid_path: "foo"}
459457

460458
kwargs[param_name] = data
461459

@@ -470,10 +468,10 @@ def test_invalid_paths(caplog, action, invalid_path, param_name):
470468
with patch("neptune_scale.sync.metadata_splitter.INVALID_VALUE_ACTION", action):
471469
if action == "raise":
472470
with pytest.raises(NeptuneUnableToLogData, match="paths must be"):
473-
next(splitter)
471+
list(splitter)
474472
else:
475473
with caplog.at_level("WARNING"):
476-
next(splitter)
474+
list(splitter)
477475
assert "paths must be" in caplog.text
478476

479477

0 commit comments

Comments
 (0)