splunk / splunk/splunk-sdk-python

JSONResultsReader iterator called on oneshot search does not iterate with for loop.

Open
#678 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
743
Forks
387
Avg merge
42m
Merged PRs (30d)
4

Description

Describe the bug
JSONResultsReader iterator called on oneshot search does not iterate with for loop.

To Reproduce
-run a oneshot search, the notice the for content/command[s] fails.

reader = JSONResultsReader(result_stream)
for item in reader:
    print(item)

Expected behavior
iterate through the results and take action on.

Logs or Screenshots
If applicable, add logs or screenshots to help explain your problem.

Splunk (please complete the following information):

  • Version: Splunk Enterprise 9.1.1
  • OS: Rocky Linux 9.6
  • Deployment: Distributed/Clustered SH's and IDX's architecture

SDK (please complete the following information):

  • Version: [2.1.0 and 2.1.1]
  • Language Runtime Version: Python 3.12.3
  • OS: Ubuntu 24.04.2 LTS

Additional context
This issue is only impacting the "oneshot" type search, with "normal" type search successfully yields an iterable "reader" for reader = JSONResultsReader(result_stream).

The workaround is to do:

reader = JSONResultsReader(result_stream)
reader2 = list(reader)
for item in reader2:
    print(item)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the provided JSONResultsReader snippet with both oneshot and normal searches, then inspect the JSONResultsReader iterator entry point and any existing tests. Done means a reader from a oneshot search supports direct for-loop iteration without first converting it to a list, with coverage for the differing search modes.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.