Skip to content

Commit

Permalink
[uss_mock] override logic preserves type of dict implementations (#775)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shastick authored Sep 20, 2024
1 parent 48b5627 commit e494363
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
23 changes: 14 additions & 9 deletions monitoring/mock_uss/f3548v21/flight_planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@

import arrow
import requests
from uas_standards.astm.f3548.v21 import api as f3548_v21
from uas_standards.astm.f3548.v21.constants import OiMaxVertices, OiMaxPlanHorizonDays
from uas_standards.interuss.automated_testing.scd.v1 import api as scd_api

from monitoring.mock_uss import webapp
from monitoring.mock_uss.config import KEY_BASE_URL
from monitoring.mock_uss.f3548v21 import utm_client
from monitoring.mock_uss.flights.database import FlightRecord, db
from monitoring.monitorlib.clients import scd as scd_client
from monitoring.monitorlib.clients.flight_planning.flight_info import (
FlightInfo,
)
from monitoring.monitorlib.fetch import QueryError
from monitoring.monitorlib.geo import AltitudeDatum, Volume3D, Altitude, DistanceUnits
from monitoring.monitorlib.scd import priority_of
from monitoring.uss_qualifier.resources.overrides import apply_overrides
from uas_standards.astm.f3548.v21 import api as f3548_v21
from uas_standards.astm.f3548.v21.constants import OiMaxVertices, OiMaxPlanHorizonDays
from uas_standards.interuss.automated_testing.scd.v1 import api as scd_api

from monitoring.mock_uss.f3548v21 import utm_client
from monitoring.mock_uss.flights.database import FlightRecord, db
from monitoring.monitorlib.clients import scd as scd_client
from monitoring.monitorlib.geotemporal import Volume4DCollection, Volume4D
from monitoring.monitorlib.locality import Locality
from monitoring.monitorlib.scd import priority_of
from monitoring.uss_qualifier.resources.overrides import apply_overrides


class PlanningError(Exception):
Expand Down Expand Up @@ -363,6 +362,12 @@ def op_intent_from_flightrecord(
op_intent, mod_op_sharing_behavior.modify_fields, parse_result=False
)

# Sanity check on the result of apply_overrides
if not isinstance(op_intent, f3548_v21.OperationalIntent):
raise Exception(
f"Expected OperationalIntent, got {type(op_intent).__name__} instead. This is likely a bug in apply_overrides."
)

return op_intent


Expand Down
9 changes: 8 additions & 1 deletion monitoring/uss_qualifier/resources/overrides.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import copy
import json
from typing import TypeVar
from implicitdict import ImplicitDict
Expand Down Expand Up @@ -26,6 +27,11 @@ def apply_overrides(


def _apply_overrides(base_object, overrides):
"""
recursively apply the passed overrides to base_object.
Note that the passed object won't be modified and copies made whenever necessary.
"""

if base_object is None:
return overrides

Expand All @@ -44,7 +50,8 @@ def _apply_overrides(base_object, overrides):

elif isinstance(overrides, dict):
if isinstance(base_object, dict):
result = {k: v for k, v in base_object.items()}
# We do a deep-copy of the base-object to preserve its type
result = copy.deepcopy(base_object)
else:
raise ValueError(
f"Attempted to override field with type {type(base_object)} with type {type(overrides)} ({json.dumps(base_object)} -> {json.dumps(overrides)})"
Expand Down

0 comments on commit e494363

Please sign in to comment.