Skip to content

Commit

Permalink
Fix: nodes without buildings causes map render crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew-Dickinson committed Oct 7, 2024
1 parent 9bdd626 commit 582a6ed
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/meshapi/tests/test_map_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,15 @@ def test_install_data(self):
)
)

nodes.append(
Node(
network_number=9820,
status=Node.NodeStatus.ACTIVE,
latitude=40.724868,
longitude=-73.987881,
)
)

for node in nodes:
node.save()

Expand Down Expand Up @@ -430,6 +439,14 @@ def test_install_data(self):
"roofAccess": True,
"panoramas": [],
},
{
"coordinates": [-73.987881, 40.724868, None],
"id": 9820,
"panoramas": [],
"requestDate": None,
"roofAccess": True,
"status": "NN assigned",
},
{
"coordinates": [-73.987881, 40.724868, None],
"id": 9821,
Expand Down
18 changes: 16 additions & 2 deletions src/meshapi/views/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from rest_framework.response import Response
from rest_framework.views import APIView

from meshapi.models import LOS, AccessPoint, Device, Install, Link, Node, Sector
from meshapi.models import LOS, AccessPoint, Building, Device, Install, Link, Node, Sector
from meshapi.serializers import (
EXCLUDED_INSTALL_STATUSES,
MapDataInstallSerializer,
Expand Down Expand Up @@ -98,14 +98,28 @@ def get_queryset(self) -> List[Install]: # type: ignore[override]
except IndexError:
representative_install = None

if representative_install:
building = representative_install.building
else:
building = node.buildings.first()

if not building:
# If we couldn't get a building from the install or node,
# make a faux one instead, to carry the lat/lon info into the serializer
building = Building(
latitude=node.latitude,
longitude=node.longitude,
altitude=node.altitude,
)

all_installs.append(
Install(
install_number=node.network_number,
node=node,
status=Install.InstallStatus.NN_REASSIGNED
if node.status == node.NodeStatus.ACTIVE
else Install.InstallStatus.REQUEST_RECEIVED,
building=representative_install.building if representative_install else node.buildings.first(),
building=building,
request_date=representative_install.request_date
if representative_install
else node.install_date,
Expand Down

0 comments on commit 582a6ed

Please sign in to comment.