Skip to content

Commit

Permalink
Merge pull request #101 from jertel/fix/jinja_deepcopy
Browse files Browse the repository at this point in the history
Prevent deepcopy of Jinja Template object
  • Loading branch information
nsano-rururu authored Apr 30, 2021
2 parents e878590 + 220c2a5 commit 4987e68
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion elastalert/test_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,18 @@ def run_rule_test(self):
with open(args.json, 'r') as data_file:
self.data = json.loads(data_file.read())
else:
hits = self.test_file(copy.deepcopy(rule_yaml), args)
# Temporarily remove the jinja_template, if it exists, to avoid deepcopy issues
template = rule_yaml.get("jinja_template")
rule_yaml["jinja_template"] = None

# Copy the rule object without the template in it
copied_rule = copy.deepcopy(rule_yaml)

# Set the template back onto the original rule object and the newly copied object
rule_yaml["jinja_template"] = template
copied_rule["jinja_template"] = template

hits = self.test_file(copied_rule, args)
if hits and args.formatted_output:
self.formatted_output['results'] = json.loads(json.dumps(hits))
if hits and args.save:
Expand Down

0 comments on commit 4987e68

Please sign in to comment.