From 78dfa36b2afcd2432051b7f8e48513e03cd2868c Mon Sep 17 00:00:00 2001 From: sadnub Date: Sat, 2 Apr 2022 08:35:30 -0400 Subject: [PATCH] fix negative index issue --- api/tacticalrmm/alerts/models.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/api/tacticalrmm/alerts/models.py b/api/tacticalrmm/alerts/models.py index 533019ff..7ca36d55 100644 --- a/api/tacticalrmm/alerts/models.py +++ b/api/tacticalrmm/alerts/models.py @@ -1,7 +1,7 @@ from __future__ import annotations import re -from typing import TYPE_CHECKING, Union, Optional +from typing import TYPE_CHECKING, Union, Optional, cast from django.contrib.postgres.fields import ArrayField from django.db import models @@ -129,11 +129,12 @@ class Alert(models.Model): alerts = cls.objects.filter( agent=agent, alert_type="availability", resolved=False ) - last_alert = alerts[-1] + + last_alert = cast(cls, alerts.last()) # cycle through other alerts and resolve for alert in alerts: - if alert.id != last_alert.id: + if alert.id != last_alert.pk: alert.resolve() return last_alert @@ -181,11 +182,11 @@ class Alert(models.Model): agent=agent if check.policy else check.agent, resolved=False, ) - last_alert = alerts[-1] + last_alert = cast(cls, alerts.last()) # cycle through other alerts and resolve for alert in alerts: - if alert.id != last_alert.id: + if alert.id != last_alert.pk: alert.resolve() return last_alert @@ -229,11 +230,11 @@ class Alert(models.Model): agent=agent if task.policy else task.agent, resolved=False, ) - last_alert = alerts[-1] + last_alert = cast(cls, alerts.last()) # cycle through other alerts and resolve for alert in alerts: - if alert.id != last_alert.id: + if alert.id != last_alert.pk: alert.resolve() return last_alert