fix negative index issue

This commit is contained in:
sadnub 2022-04-02 08:35:30 -04:00
parent dc05d87b44
commit 78dfa36b2a
1 changed files with 8 additions and 7 deletions

View File

@ -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