From 381279678b48aed9c0a02bcd206c994c8027554f Mon Sep 17 00:00:00 2001 From: shivamsharma Date: Wed, 27 May 2026 01:34:53 +0530 Subject: [PATCH 1/2] fix: stream records lazily in write_records and _execute_chunk_v2 --- splunklib/searchcommands/generating_command.py | 6 +----- splunklib/searchcommands/internals.py | 3 ++- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/splunklib/searchcommands/generating_command.py b/splunklib/searchcommands/generating_command.py index 33426544..cbb1a252 100644 --- a/splunklib/searchcommands/generating_command.py +++ b/splunklib/searchcommands/generating_command.py @@ -208,16 +208,12 @@ def _execute(self, ifile, process): def _execute_chunk_v2(self, process, chunk): count = 0 - records = [] for row in process: - records.append(row) + self._record_writer.write_record(row) count += 1 if count == self._record_writer._maxresultrows: break - for row in records: - self._record_writer.write_record(row) - if count == self._record_writer._maxresultrows: self._finished = False else: diff --git a/splunklib/searchcommands/internals.py b/splunklib/searchcommands/internals.py index 40e46855..e9a83870 100644 --- a/splunklib/searchcommands/internals.py +++ b/splunklib/searchcommands/internals.py @@ -527,7 +527,8 @@ def write_record(self, record): def write_records(self, records): self._ensure_validity() - records = [] if records is NotImplemented else list(records) + if records is NotImplemented: + return write_record = self._write_record for record in records: write_record(record) From ae7f1d409377d72ca76bf58b66bdb991dc478f9d Mon Sep 17 00:00:00 2001 From: shivamsharma Date: Fri, 29 May 2026 20:56:27 +0530 Subject: [PATCH 2/2] fix: use public maxresultrows property to fix lint errors --- splunklib/searchcommands/generating_command.py | 4 ++-- splunklib/searchcommands/internals.py | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/splunklib/searchcommands/generating_command.py b/splunklib/searchcommands/generating_command.py index cbb1a252..1de90354 100644 --- a/splunklib/searchcommands/generating_command.py +++ b/splunklib/searchcommands/generating_command.py @@ -211,10 +211,10 @@ def _execute_chunk_v2(self, process, chunk): for row in process: self._record_writer.write_record(row) count += 1 - if count == self._record_writer._maxresultrows: + if count == self._record_writer.maxresultrows: break - if count == self._record_writer._maxresultrows: + if count == self._record_writer.maxresultrows: self._finished = False else: self._finished = True diff --git a/splunklib/searchcommands/internals.py b/splunklib/searchcommands/internals.py index e9a83870..e9aa15ea 100644 --- a/splunklib/searchcommands/internals.py +++ b/splunklib/searchcommands/internals.py @@ -462,6 +462,10 @@ def __init__(self, ofile, maxresultrows=None): self._committed_record_count = 0 self.custom_fields = set() + @property + def maxresultrows(self): + return self._maxresultrows + @property def is_flushed(self): return self._flushed