From 808e1cd3b68a77d9da56da7b06d8ec317f388200 Mon Sep 17 00:00:00 2001 From: CaroLS <5789321+kittylon@users.noreply.github.com> Date: Mon, 2 Mar 2026 16:42:38 +0100 Subject: [PATCH 1/2] fix: dump the entire data into one JSON, to send the Content-Length header --- verdin/datasource.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/verdin/datasource.py b/verdin/datasource.py index 03115cb..976a510 100644 --- a/verdin/datasource.py +++ b/verdin/datasource.py @@ -147,9 +147,7 @@ def append_ndjson(self, records: List[Dict]) -> requests.Response: :return: The HTTP response """ - def _ndjson_iterator(): - for record in records: - yield json.dumps(record) + "\n" + data = "".join(json.dumps(record) + "\n" for record in records) LOG.debug( "appending %d ndjson records to %s via %s", @@ -160,7 +158,7 @@ def _ndjson_iterator(): response = self._datasources_api.append( name=self.canonical_name, format="ndjson", - data=_ndjson_iterator(), + data=data, ) return response._response From 30e81892f8de10c96c8e4c4b9354d14eb80a4dde Mon Sep 17 00:00:00 2001 From: CaroLS <5789321+kittylon@users.noreply.github.com> Date: Mon, 2 Mar 2026 19:27:22 +0100 Subject: [PATCH 2/2] feat: add test to the Datasource append_ndjson --- tests/test_datasource.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_datasource.py b/tests/test_datasource.py index 5510c5a..894f9f8 100644 --- a/tests/test_datasource.py +++ b/tests/test_datasource.py @@ -44,6 +44,28 @@ def handler(request): assert response.ok + def test_append_ndjson(self, httpserver: HTTPServer): + ds = Datasource("mydatasource", "123456", api=httpserver.url_for("/")) + + records = [{"key": "foo", "value": "bar"}, {"key": "baz", "value": "ed"}] + expected_body = '{"key": "foo", "value": "bar"}\n{"key": "baz", "value": "ed"}\n' + + httpserver.expect_request( + "/v0/datasources", + query_string={ + "name": "mydatasource", + "mode": "append", + "format": "ndjson", + }, + data=expected_body, + headers={"Content-Length": str(len(expected_body.encode()))}, + ).respond_with_data("", 200) + + response = ds.append_ndjson(records) + httpserver.check() + assert response.ok + + class TestFileDatasource: def test_append(self, tmp_path): file_path = tmp_path / "myfile.csv"