diff --git a/quads/api_v2.py b/quads/api_v2.py index 32b59da51..c5ae08172 100644 --- a/quads/api_v2.py +++ b/quads/api_v2.py @@ -379,10 +379,12 @@ def POST(self, **data): _host = data["host"] _host_obj = Host.objects(name=_host).first() + if not _host_obj: + result.append(f"Host {_host} is not defined") broken_hosts = Host.objects(broken=True) if _host_obj in broken_hosts: - result.append(f"Host {_host_obj.name} is in broken state") + result.append(f"Host {_host_obj.name} does not exist") # Check if there were data validation errors if result: diff --git a/quads/model.py b/quads/model.py index c27a2d07a..a09efcd87 100644 --- a/quads/model.py +++ b/quads/model.py @@ -283,6 +283,8 @@ def insert_schedule(self, cloud, host, start, end): @queryset_manager def is_host_available(self, queryset, host, start, end, exclude=None): _host = Host.objects(name=host).first() + if not _host: + return False if _host.broken or _host.retired: return False _query = Q(host=_host)