Skip to content

Commit

Permalink
Avoid mutating filter when checking it
Browse files Browse the repository at this point in the history
  • Loading branch information
hmpf committed Apr 16, 2024
1 parent b0833ab commit f5c96b4
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/argus/notificationprofile/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class FilterWrapper:

def __init__(self, filterblob):
self.fallback_filter = getattr(settings, "ARGUS_FALLBACK_FILTER", {})
self.filter = filterblob
self.filter = filterblob.copy()

def _get_tristate(self, tristate):
fallback_filter = self.fallback_filter.get(tristate, None)
Expand Down Expand Up @@ -204,15 +204,15 @@ def filtered_incidents(self):

def incidents_with_source_systems(self, data=None):
if not data:
data = self.filter
data = self.filter.copy()
source_list = data.pop("sourceSystemIds", [])
if source_list:
return self.all_incidents.filter(source__in=source_list).distinct()
return self.all_incidents.distinct()

def source_system_fits(self, incident: Incident, data=None):
if not data:
data = self.filter
data = self.filter.copy()
source_list = data.pop("sourceSystemIds", [])
if not source_list:
# We're not limiting on sources!
Expand All @@ -221,15 +221,15 @@ def source_system_fits(self, incident: Incident, data=None):

def incidents_with_tags(self, data=None):
if not data:
data = self.filter
data = self.filter.copy()
tags_list = data.pop("tags", [])
if tags_list:
return self.all_incidents.from_tags(*tags_list)
return self.all_incidents.distinct()

def tags_fit(self, incident: Incident, data=None):
if not data:
data = self.filter
data = self.filter.copy()
tags_list = data.pop("tags", [])
if not tags_list:
# We're not limiting on tags!
Expand All @@ -242,7 +242,7 @@ def incidents_fitting_tristates(
data=None,
):
if not data:
data = self.filter
data = self.filter.copy()
fitting_incidents = self.all_incidents
filter_open = data.pop("open", None)
filter_acked = data.pop("acked", None)
Expand All @@ -264,7 +264,7 @@ def incidents_fitting_tristates(

def incidents_fitting_maxlevel(self, data=None):
if not data:
data = self.filter
data = self.filter.copy()
maxlevel = data.pop("maxlevel", None)
if not maxlevel:
return self.all_incidents.distinct()
Expand All @@ -273,7 +273,7 @@ def incidents_fitting_maxlevel(self, data=None):
def incident_fits(self, incident: Incident):
if self.is_empty:
return False # Filter is empty!
data = self.filter
data = self.filter.copy()
checks = {}
checks["source"] = self.source_system_fits(incident, data)
checks["tags"] = self.tags_fit(incident, data)
Expand Down

0 comments on commit f5c96b4

Please sign in to comment.