Skip to content

Commit 68223a1

Browse files
committed
🐛 Ensure only valid arguments are sent to the server
1 parent 2076f5e commit 68223a1

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

simvue/api/objects/alert/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def __init__(self, identifier: str | None = None, **kwargs) -> None:
3131
"""Retrieve an alert from the Simvue server by identifier"""
3232
self._label = "alert"
3333
super().__init__(identifier=identifier, **kwargs)
34+
self._local_only_args = ["frequency", "pattern", "aggregation"]
3435

3536
def compare(self, other: "AlertBase") -> bool:
3637
"""Compare this alert to another"""

simvue/api/objects/alert/metrics.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ def __init__(self, identifier: str | None = None, **kwargs) -> None:
3030
"""Connect to a local or remote threshold alert by identifier"""
3131
self.alert = MetricThresholdAlertDefinition(self)
3232
super().__init__(identifier, **kwargs)
33+
self._local_only_args += [
34+
"rule",
35+
"window",
36+
"metric",
37+
"threshold",
38+
]
3339

3440
@classmethod
3541
def get(
@@ -117,6 +123,13 @@ def __init__(self, identifier: str | None = None, **kwargs) -> None:
117123
"""Connect to a local or remote threshold alert by identifier"""
118124
self.alert = MetricRangeAlertDefinition(self)
119125
super().__init__(identifier, **kwargs)
126+
self._local_only_args += [
127+
"rule",
128+
"window",
129+
"metric",
130+
"range_low",
131+
"range_high",
132+
]
120133

121134
def compare(self, other: "MetricsRangeAlert") -> bool:
122135
"""Compare two MetricRangeAlerts"""

simvue/api/objects/artifact/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def __init__(
5454
self._label = "artifact"
5555
self._endpoint = f"{self._label}s"
5656
super().__init__(identifier=identifier, _read_only=_read_only, **kwargs)
57+
self._local_only_args += ["storage", "file_path", "runs"]
5758

5859
# If the artifact is an online instance, need a place to store the response
5960
# from the initial creation

simvue/api/objects/base.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ def __init__(
197197
self._read_only: bool = _read_only
198198
self._is_set: bool = False
199199
self._endpoint: str = getattr(self, "_endpoint", f"{self._label}s")
200+
201+
# For simvue object initialisation, unlike the server there is no nested
202+
# arguments, however this means that there are extra keys during post which
203+
# need removing, this attribute handles that and should be set in subclasses.
204+
self._local_only_args: list[str] = []
205+
200206
self._identifier: str | None = (
201207
identifier if identifier is not None else f"offline_{uuid.uuid1()}"
202208
)
@@ -633,6 +639,10 @@ def _post_single(
633639
if not is_json:
634640
kwargs = msgpack.packb(data or kwargs, use_bin_type=True)
635641

642+
# Remove any extra keys
643+
for key in self._local_only_args:
644+
_ = (data or kwargs).pop(key, None)
645+
636646
_response = sv_post(
637647
url=f"{self._base_url}",
638648
headers=self._headers | {"Content-Type": "application/msgpack"},
@@ -670,6 +680,11 @@ def _post_single(
670680
def _put(self, **kwargs) -> dict[str, typing.Any]:
671681
if not self.url:
672682
raise RuntimeError(f"Identifier for instance of {self._label} Unknown")
683+
684+
# Remove any extra keys
685+
for key in self._local_only_args:
686+
_ = kwargs.pop(key, None)
687+
673688
_response = sv_put(
674689
url=f"{self.url}", headers=self._headers, data=kwargs, is_json=True
675690
)

simvue/run.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,6 @@ def init(
766766
self._sv_obj.alerts = []
767767
self._sv_obj.created = time.time()
768768
self._sv_obj.notifications = notification
769-
self._sv_obj._staging["folder_id"] = self._folder.id
770769

771770
if self._status == "running":
772771
self._sv_obj.system = get_system()

0 commit comments

Comments
 (0)