Skip to content

Commit 1bfc8f6

Browse files
committed
RDBC-999 Fix failing tests
1 parent 7bf4508 commit 1bfc8f6

4 files changed

Lines changed: 30 additions & 10 deletions

File tree

.github/workflows/RavenClient.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
RAVENDB_PYTHON_TEST_SERVER_CERTIFICATE_PATH: certs/server.pfx
2626
RAVENDB_PYTHON_TEST_CLIENT_CERTIFICATE_PATH: certs/python.pem
2727
RAVENDB_PYTHON_TEST_CA_PATH: /usr/local/share/ca-certificates/ca.crt
28-
RAVENDB_PYTHON_TEST_HTTPS_SERVER_URL: https://localhost:7326
28+
RAVENDB_PYTHON_TEST_HTTPS_SERVER_URL: https://localhost:8081
2929

3030
strategy:
3131
matrix:
@@ -85,11 +85,9 @@ jobs:
8585
run: mkdir RavenDB/Server/certs && cp certs/server.pfx RavenDB/Server/certs/
8686

8787
- name: Install black linter
88-
if: ${{ matrix.python-version != '3.7' }}
8988
run: pip install black
9089

9190
- name: Check code format
92-
if: ${{ matrix.python-version != '3.7' }}
9391
run: black --check .
9492

9593
- name: Run tests

ravendb/documents/conventions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def __init__(self):
8787
self.wait_for_indexes_after_save_changes_timeout = timedelta(seconds=15)
8888
self.wait_for_replication_after_save_changes_timeout = timedelta(seconds=15)
8989
self.wait_for_non_stale_results_timeout = timedelta(seconds=15)
90+
self.max_empty_lines_in_jsonl_stream = 100
9091

9192
# Balancing
9293
self._load_balancer_context_seed: Optional[int] = None

ravendb/documents/session/operations/stream.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ def set_result(self, response: StreamResultResponse) -> Iterator[Dict]:
7373
if response is None or response.stream_iterator is None:
7474
raise IndexDoesNotExistException("The index does not exists, failed to stream results")
7575

76-
parser = JSONLRavenStreamParser(response.stream_iterator)
76+
parser = JSONLRavenStreamParser(
77+
response.stream_iterator, self._session.conventions.max_empty_lines_in_jsonl_stream
78+
)
7779

7880
if self._is_query_stream:
7981
self._handle_stream_query_stats(parser, self._statistics)

ravendb/tools/parsers.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
from json import JSONDecodeError
23
from typing import Any, Iterator, Optional, Dict
34
from decimal import InvalidOperation
45

@@ -249,16 +250,34 @@ def unescape(s):
249250

250251

251252
class JSONLRavenStreamParser:
252-
def __init__(self, stream: Iterator):
253+
def __init__(self, stream: Iterator, max_empty_lines: int = 100):
253254
self._stream = stream
254255
self._unused_buffer: Optional[Dict] = None
256+
self._max_empty_lines = max_empty_lines
255257

256258
def _get_next_json_dict(self) -> Dict:
257-
return (
258-
self._unused_buffer
259-
if self._unused_buffer is not None
260-
else json.loads(self._stream.__next__().decode("utf-8"))
261-
)
259+
if self._unused_buffer is not None:
260+
return self._unused_buffer
261+
262+
empty_line_count = 0
263+
while True:
264+
json_data = self._stream.__next__().decode("utf-8").strip()
265+
266+
# Skip empty lines (standard in JSONL format)
267+
if not json_data:
268+
empty_line_count += 1
269+
if empty_line_count >= self._max_empty_lines:
270+
raise RuntimeError(
271+
f"Received {self._max_empty_lines} consecutive empty lines in JSONL stream. "
272+
f"You can configure the maximum number of empty lines to ignore "
273+
f"using DocumentConventions.max_empty_lines_in_jsonl_stream."
274+
)
275+
continue
276+
277+
try:
278+
return json.loads(json_data)
279+
except JSONDecodeError as e:
280+
raise RuntimeError(f"Failed to parse JSON from stream: {json_data}") from e
262281

263282
def purge_cache(self) -> None:
264283
self._unused_buffer = None

0 commit comments

Comments
 (0)