Skip to content

Commit 41ecf20

Browse files
committed
fix: add correct count of attributes in filter tab count (#165)
1 parent 01b04d1 commit 41ecf20

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

alerta/models/filter_tab.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,21 @@ def to_isoformat(date: datetime):
8686
if 'to' in value:
8787
to_time = datetime.fromtimestamp(value['to'], tz=UTC)
8888
data.append(('to-date', to_isoformat(to_time)))
89-
if key == 'attributes':
90-
for attr_key, attr_value in value.items():
91-
if isinstance(attr_value, list):
92-
for item in attr_value:
89+
if 'attributes' in key:
90+
if key == 'attributes':
91+
for attr_key, attr_value in value.items():
92+
if isinstance(attr_value, list):
93+
for item in attr_value:
94+
data.append((f'attributes.{attr_key}', item))
95+
else:
96+
data.append((f'attributes.{attr_key}', attr_value))
97+
else:
98+
key, attr_key = key.split('.')
99+
if isinstance(value, list):
100+
for item in value:
93101
data.append((f'attributes.{attr_key}', item))
94102
else:
95-
data.append((f'attributes.{attr_key}', attr_value))
103+
data.append((f'attributes.{attr_key}', value))
96104
elif key not in VALID_PARAMS or isinstance(value, dict):
97105
continue
98106
elif isinstance(value, list):
@@ -106,7 +114,7 @@ def to_isoformat(date: datetime):
106114
def __repr__(self) -> str:
107115
return f'AlertTab(name={self.name}, index={self.index}, filter={self.filter},'
108116

109-
@ classmethod
117+
@classmethod
110118
def from_db(cls, rec) -> 'FilterTab':
111119
return FilterTab(
112120
name=rec.name,
@@ -124,7 +132,7 @@ def create_all(tabs: list['FilterTab']) -> list['FilterTab']:
124132
return [FilterTab.from_db(tab) for tab in db.create_filter_tabs(tabs)]
125133

126134
# get a filter tab
127-
@ staticmethod
135+
@staticmethod
128136
def find_by_id(id: str):
129137
return FilterTab.from_db(db.get_filter_tab(id))
130138

@@ -140,7 +148,7 @@ def update_all(tabs: list['FilterTab']):
140148
def update_indexes(tabs):
141149
return db.update_filter_tab_indexes(tabs)
142150

143-
@ staticmethod
151+
@staticmethod
144152
def find_all() -> list['FilterTab']:
145153
return [
146154
FilterTab.from_db(notification_channel)

0 commit comments

Comments
 (0)