Skip to content

Commit

Permalink
Catching MultipleObjectsReturned, logging that only a single map is s…
Browse files Browse the repository at this point in the history
…upported (#730)

* Catching MultipleObjectsReturned, logging that only a single map is supported

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Lint

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

---------

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>
  • Loading branch information
aaronchongth authored Jul 27, 2023
1 parent 22355c1 commit ac76ae9
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/api-server/api_server/rmf_io/health_watchdog.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from rx.core.typing import Disposable
from rx.scheduler.scheduler import Scheduler
from rx.subject.behaviorsubject import BehaviorSubject
from tortoise.exceptions import MultipleObjectsReturned

from api_server.models import (
BuildingMap,
Expand Down Expand Up @@ -121,7 +122,21 @@ def watch(id_: str, obs: Observable):
self._combine_most_critical(door_mode_health),
).subscribe(self.rmf.door_health.on_next, scheduler=self.scheduler)

ttm_map = await ttm.BuildingMap.get_or_none()
try:
ttm_map = await ttm.BuildingMap.get_or_none()
except MultipleObjectsReturned:
ttm_maps = await ttm.BuildingMap.all()
map_names = [BuildingMap.from_tortoise(m).name for m in ttm_maps]
self.logger.error(
"There appears to be multiple building maps "
f"available: {map_names}. Please ensure that "
"there is only a single building_map_server "
"running in this deployment, start a fresh "
"database or remove the rogue map, before "
"starting the API server again."
)
raise

if ttm_map is None:
doors = []
else:
Expand Down

0 comments on commit ac76ae9

Please sign in to comment.