Added API guardrails with copy
API has been update to return copies when returning immutable objects to avoid passing internal references to the user that could then modify them, breaking the internal state. Even if the copy operation is obsolete in some cases, it is kept in as a safety should the API functions be modified which would cause a return reference issue, the concerned API methods are not to be requested at high frequency either way so the performance hit is estimated to be minimal, the only API method that may be queried at a high freqency is fetching live values which are returned as floats which are immutable and therefore not concerned
This commit is contained in:
4 files changed
+29
-22
No files matched your search
@@ -11,7 +11,10 @@ from zipfile import ZIP_DEFLATED, ZipFile
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from dynalab_core.errors import DLPakError, DLUnitError
|
||||
from dynalab_core.protocols.packets.handshake import SignalDescriptor
|
||||
from dynalab_core.protocols.packets.handshake import (
|
||||
JsonSignalDescriptor,
|
||||
SignalDescriptor,
|
||||
)
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@@ -19,8 +22,8 @@ log = logging.getLogger(__name__)
|
||||
|
||||
class DeriveManifest(BaseModel):
|
||||
unit_uuid: UUID
|
||||
input_signals: list[SignalDescriptor] = Field(default_factory=list)
|
||||
return_signal: SignalDescriptor
|
||||
input_signals: list[JsonSignalDescriptor] = Field(default_factory=list)
|
||||
return_signal: JsonSignalDescriptor
|
||||
comments: str = ""
|
||||
|
||||
|
||||
@@ -42,10 +45,13 @@ class DLUnit:
|
||||
return_signal: SignalDescriptor,
|
||||
) -> None:
|
||||
|
||||
json_input_signals = [signal.to_json() for signal in input_signals]
|
||||
json_return_signal = return_signal.to_json()
|
||||
|
||||
self._manifest = DeriveManifest(
|
||||
unit_uuid=unit_uuid,
|
||||
input_signals=input_signals,
|
||||
return_signal=return_signal,
|
||||
input_signals=json_input_signals,
|
||||
return_signal=json_return_signal,
|
||||
)
|
||||
|
||||
def read(self, file: str | Path) -> Self:
|
||||
|
||||
Reference in new issue
Block a user