-
Notifications
You must be signed in to change notification settings - Fork 522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] Handle formatting empty list #4086
Conversation
Bug - GuidelinesThese guidelines serve as a reminder set of considerations when addressing a bug in the code. Documentation and Context
Code Standards and Practices
Testing
Additional Checks
|
(cherry picked from commit df31c00)
(cherry picked from commit df31c00)
(cherry picked from commit df31c00)
(cherry picked from commit df31c00)
(cherry picked from commit df31c00)
(cherry picked from commit df31c00)
@@ -161,7 +161,7 @@ def dump_list(self, v): | |||
dump.append(' ' * 4 + self.dump_value(item)) | |||
return '[\n{},\n]'.format(',\n'.join(dump)) | |||
|
|||
if all(isinstance(i, dict) for i in v): | |||
if v and all(isinstance(i, dict) for i in v): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
huh, nice
This should not be handled in the formatter and should be rolled back. This will now blindly strip all empty lists when dumping. Empty lists are valid toml structures and so should not be stripped at all. The proper way to handle this would have been to strip the object itself (the rule) of any unwanted empty lists, similar to: detection-rules/detection_rules/utils.py Lines 40 to 45 in df31c00
or detection-rules/detection_rules/mixins.py Lines 31 to 39 in df31c00
|
This reverts commit df31c00.
Pull Request
Issue link(s):
Related to #4066
Related to https://elasticstack.slack.com/archives/C06TE19EP09/p1726588617531219?thread_ts=1726587438.668979&cid=C06TE19EP09
Summary - What I changed
How To Test
Running
python -m detection_rules kibana --space main export-rules -d custom_rules
for a custom rule to see the broken output.Sample Rule After Export without Fix
Sample Rule After Export w/Fix
Checklist
bug
,enhancement
,Rule: New
,Rule: Deprecation
,Rule: Promote
,Rule: Tuning
,Hunt: New
, orHunt: Tuning
so guidelines can be generatedmeta:rapid-merge
label if planning to merge within 24 hours