Passing this into ConnectionHandler.import_connection_data() can mutate the original request. Speficially, endpoints[n].port_id gets renamed to endpoints.id and endpoints[n].vlan becomes endpoints[n].vlan_range.
import pprint
from sdx_datamodel.parsing.connectionhandler import ConnectionHandler
ConnectionHandler().import_connection_data(request)
pprint.pprint(request)
This is surprising behavior and mutating data like this makes it harder to reason about program behavior. Further, we'll be unable to access the original request, should we need it (such as when needing to look up disallowed VLANs: https://github.com/atlanticwave-sdx/pce/issues/208). Although we still have the data we need in a slightly different form, switching things in this manner is probably not the best way to do this.
(ConnectionHandler._make_port() is the likely culprit. Perhaps using Pydantic to validate connection requests would be a good idea.)
Consider this connection request:
Passing this into
ConnectionHandler.import_connection_data()
can mutate the original request. Speficially,endpoints[n].port_id
gets renamed toendpoints.id
andendpoints[n].vlan
becomesendpoints[n].vlan_range
.The above code prints:
This is surprising behavior and mutating data like this makes it harder to reason about program behavior. Further, we'll be unable to access the original request, should we need it (such as when needing to look up disallowed VLANs: https://github.com/atlanticwave-sdx/pce/issues/208). Although we still have the data we need in a slightly different form, switching things in this manner is probably not the best way to do this.
(
ConnectionHandler._make_port()
is the likely culprit. Perhaps using Pydantic to validate connection requests would be a good idea.)