Skip to content

Commit

Permalink
fix: Empty blackout values should be null (#1643)
Browse files Browse the repository at this point in the history
  • Loading branch information
satterly committed Dec 5, 2021
1 parent f3c51f3 commit 5911e68
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions alerta/models/blackout.py
Expand Up @@ -25,6 +25,14 @@ class Blackout:
def __init__(self, environment: str, **kwargs) -> None:
if not environment:
raise ValueError('Missing mandatory value for "environment"')
if kwargs.get('resource') == '':
raise ValueError('resource can not be an empty string')
if kwargs.get('event') == '':
raise ValueError('event can not be an empty string')
if kwargs.get('group') == '':
raise ValueError('group can not be an empty string')
if kwargs.get('origin') == '':
raise ValueError('origin can not be an empty string')

start_time = kwargs.get('start_time', None) or datetime.utcnow()
if kwargs.get('end_time', None):
Expand Down Expand Up @@ -53,6 +61,8 @@ def __init__(self, environment: str, **kwargs) -> None:
self.text = kwargs.get('text', None)

if self.environment:
self.priority = 0
if self.origin:
self.priority = 1
if self.resource and not self.event:
self.priority = 2
Expand Down Expand Up @@ -166,7 +176,7 @@ def from_document(cls, doc: Dict[str, Any]) -> 'Blackout':
event=doc.get('event', None),
group=doc.get('group', None),
tags=doc.get('tags', list()),
origin=doc.get('origin'),
origin=doc.get('origin', None),
customer=doc.get('customer', None),
start_time=doc.get('startTime', None),
end_time=doc.get('endTime', None),
Expand All @@ -184,11 +194,11 @@ def from_record(cls, rec) -> 'Blackout':
priority=rec.priority,
environment=rec.environment,
service=rec.service,
resource=rec.resource,
event=rec.event,
group=rec.group,
resource=rec.resource if rec.resource != '' else None,
event=rec.event if rec.event != '' else None,
group=rec.group if rec.group != '' else None,
tags=rec.tags,
origin=rec.origin,
origin=rec.origin if rec.origin != '' else None,
customer=rec.customer,
start_time=rec.start_time,
end_time=rec.end_time,
Expand Down

0 comments on commit 5911e68

Please sign in to comment.