Skip to content

Commit 686d32a

Browse files
committed
Fix GET detail route when id is array (single vs multi-id)
Use /endpoint/{id}/ only for scalar or one-element id; keep list endpoint and pass id as query params for multiple ids. Fixes 404 with stackstorm-netbox v3.4.x.
1 parent 69cb91a commit 686d32a

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

actions/run.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,27 @@ def run(self, endpoint_uri, http_verb, get_detail_route_eligible, fail_non_2xx,
1515
StackStorm action entry point.
1616
"""
1717
if http_verb == "get":
18-
if kwargs.get("id", False) and get_detail_route_eligible:
19-
# modify the `endpoint_uri` to use the detail route
20-
endpoint_uri = "{}{}/".format(endpoint_uri, str(kwargs.pop("id")))
21-
self.logger.debug(
22-
"endpoint_uri transformed to {} because id was passed".format(endpoint_uri)
23-
)
18+
if get_detail_route_eligible and "id" in kwargs:
19+
id_param = kwargs["id"]
20+
# Normalize id: scalar or one-element list -> detail route; multi-element list -> list filter
21+
if isinstance(id_param, (list, tuple)):
22+
if len(id_param) == 1:
23+
detail_id = id_param[0]
24+
kwargs.pop("id")
25+
endpoint_uri = "{}{}/".format(endpoint_uri, str(detail_id))
26+
self.logger.debug(
27+
"endpoint_uri transformed to {} because id was passed (single from list)".format(
28+
endpoint_uri
29+
)
30+
)
31+
# else: len > 1 -> keep id in kwargs for list filter (?id=1&id=2), do not change endpoint_uri
32+
else:
33+
# scalar id -> detail route
34+
detail_id = kwargs.pop("id")
35+
endpoint_uri = "{}{}/".format(endpoint_uri, str(detail_id))
36+
self.logger.debug(
37+
"endpoint_uri transformed to {} because id was passed".format(endpoint_uri)
38+
)
2439

2540
if kwargs.get("save_in_key_store") and not kwargs.get("save_in_key_store_key_name"):
2641
return (False, "save_in_key_store_key_name MUST be used with save_in_key_store!")

0 commit comments

Comments
 (0)