Skip to content

Commit

Permalink
fix: Postgres' json_agg return Null instead of empty list if no data (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirFilonov authored Dec 9, 2024
1 parent 3bbc849 commit 136a383
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions keep/api/core/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -3014,10 +3014,12 @@ def get_incidents_meta_for_tenant(tenant_id: str) -> dict:
if not results:
return {}

assignees, sources, affected_services = results

return {
"assignees": list(filter(bool, results.assignees)),
"sources": list(filter(bool, results.sources)),
"services": list(filter(bool, results.affected_services)),
"assignees": list(filter(bool, assignees)) if assignees else [],
"sources": list(filter(bool, sources)) if sources else [],
"services": list(filter(bool, affected_services)) if affected_services else [],
}
return {}

Expand Down Expand Up @@ -4628,4 +4630,4 @@ def set_last_alert(
)

session.add(last_alert)
transaction.commit()
transaction.commit()
2 changes: 1 addition & 1 deletion tests/test_incidents.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,4 +859,4 @@ def test_cross_tenant_exposure_issue_2768(db_session, create_alert):
)
assert incident_tenant_2.alerts_count == 1
assert total_incident_tenant_2_alerts == 1
assert len(incident_tenant_2_alerts) == 1
assert len(incident_tenant_2_alerts) == 1

0 comments on commit 136a383

Please sign in to comment.