Skip to content

Commit

Permalink
core/endpoint: Get choices from PUT if POST missing
Browse files Browse the repository at this point in the history
If the API token is not allowed to POST on a particular endpoint, choices won't
be returned in `.actions.POST`, but we can still get them in `.actions.PUT`.

This commit falls back to getting choices from `.actions.PUT` instead of
raising an exception when `.actions.POST` is missing.
  • Loading branch information
BenoitKnecht committed Nov 3, 2023
1 parent e56aba1 commit dddd5fa
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pynetbox/core/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,9 +585,10 @@ def choices(self):
token=self.api.token,
http_session=self.api.http_session,
).options()
try:
post_data = req["actions"]["POST"]
except KeyError:

actions = req.get("actions", {})
post_data = actions.get("POST") or actions.get("PUT")
if post_data is None:
raise ValueError(
"Unexpected format in the OPTIONS response at {}".format(self.url)
)
Expand Down

0 comments on commit dddd5fa

Please sign in to comment.