Problem
Several state variables in bin/goatsearch.py are initialized at the class definition level (lines 29-53):
class goatsearch(GeneratingCommand):
# ... options ...
access_token = False # Line 29
v_client_id = False # Line 31
v_tenant = False # Line 32
v_workspace = False # Line 33
headers = False # Line 35
search_context = False # Line 36
baseuri = False # Line 38
job_id = False # Line 39
event_log = [] # Line 41 - MUTABLE!
queue_notice = False # Line 43
running_notice = False # Line 44
complete_notice = False # Line 45
job_complete = False # Line 47
total_event_count = 0 # Line 49
offset = 0 # Line 50
api_limit = 200 # Line 51
can_run = False # Line 53
In Python, class-level variable assignments create class attributes that are shared across all instances. The Python Official Tutorial (Section 9.3.5) explicitly warns:
"Shared data can have possibly surprising effects with mutable objects such as lists and dictionaries."
Of particular concern is event_log = [] on line 41 — this is a mutable list that would be shared across instances if the class were reused.
Practical Risk
While Splunk's search command framework likely creates fresh instances per search execution, relying on this behavior is fragile:
- Future framework changes could introduce pooling
- Testing becomes harder (state bleeds between tests)
- Code intent is unclear to readers
Proposed Solution
Move state initialization to prepare() or add an __init__ method:
def prepare(self):
# Reset all instance state
self.access_token = None
self.v_client_id = None
self.v_tenant = None
self.v_workspace = None
self.headers = None
self.search_context = None
self.baseuri = None
self.job_id = None
self.event_log = [] # Fresh list per instance
self.queue_notice = False
self.running_notice = False
self.complete_notice = False
self.job_complete = False
self.total_event_count = 0
self.offset = 0
self.can_run = False
# ... existing prepare() logic ...
Note: Keep api_limit at class level if it's intended as a constant/default.
Acceptance Criteria
References
Related Code
bin/goatsearch.py lines 29-53
Problem
Several state variables in
bin/goatsearch.pyare initialized at the class definition level (lines 29-53):In Python, class-level variable assignments create class attributes that are shared across all instances. The Python Official Tutorial (Section 9.3.5) explicitly warns:
Of particular concern is
event_log = []on line 41 — this is a mutable list that would be shared across instances if the class were reused.Practical Risk
While Splunk's search command framework likely creates fresh instances per search execution, relying on this behavior is fragile:
Proposed Solution
Move state initialization to
prepare()or add an__init__method:Note: Keep
api_limitat class level if it's intended as a constant/default.Acceptance Criteria
event_log) moved to instance initializationprepare()api_limit) documented as intentionalReferences
Related Code
bin/goatsearch.pylines 29-53