Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaking change in custom scripts called with api on v4.x #16129

Closed
Leon-Pay opened this issue May 14, 2024 · 3 comments
Closed

Breaking change in custom scripts called with api on v4.x #16129

Leon-Pay opened this issue May 14, 2024 · 3 comments
Labels
status: duplicate This issue has already been raised type: bug A confirmed report of unexpected behavior in the application

Comments

@Leon-Pay
Copy link

Deployment Type

Self-hosted

NetBox Version

v4.0.1

Python Version

3.11

Steps to Reproduce

Create a custom script and try to call it from the API. The old url has changed to an id and when calling the script from the API it will throw an error.

Expected Behavior

The script runs when called with the API.
The api url used to be /api/extras/scripts/ssl_checker_custom_script.SSLChecker/
Like: https://github.com/netbox-community/netbox/blob/develop/docs/customization/custom-scripts.md#via-the-api

Observed Behavior

Url has changed to /api/extras/scripts/1

Trying to run the custom script, with the new url will throw an error:

const url = '/api/extras/scripts/1/';
const sendData = { data: { certificate: id }, commit: true };

fetch(url, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-CSRFToken': csrf_token
  },
  body: JSON.stringify(sendData)
})
netbox-worker-1        | 14:42:31 default: extras.scripts.run_script(commit=True, data={'certificate': '2'}, job=<Job: a00b207c-ce2c-422e-b0f7-8acbac05b42d>, request=<utilities.request.NetBoxFakeRequest object at 0xffff77998d50>) (a00b207c-ce2c-422e-b0f7-8acbac05b42d)
netbox-1               | Internal Server Error: /api/extras/scripts/1/
netbox-1               | Traceback (most recent call last):
netbox-1               |   File "/opt/netbox/venv/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
netbox-1               |     response = get_response(request)
netbox-1               |                ^^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "/opt/netbox/venv/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response
netbox-1               |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
netbox-1               |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "/opt/netbox/venv/lib/python3.11/site-packages/django/views/decorators/csrf.py", line 65, in _view_wrapper
netbox-1               |     return view_func(request, *args, **kwargs)
netbox-1               |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "/opt/netbox/venv/lib/python3.11/site-packages/rest_framework/viewsets.py", line 124, in view
netbox-1               |     return self.dispatch(request, *args, **kwargs)
netbox-1               |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "/opt/netbox/venv/lib/python3.11/site-packages/rest_framework/views.py", line 509, in dispatch
netbox-1               |     response = self.handle_exception(exc)
netbox-1               |                ^^^^^^^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "/opt/netbox/venv/lib/python3.11/site-packages/rest_framework/views.py", line 469, in handle_exception
netbox-1               |     self.raise_uncaught_exception(exc)
netbox-1               |   File "/opt/netbox/venv/lib/python3.11/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
netbox-1               |     raise exc
netbox-1               |   File "/opt/netbox/venv/lib/python3.11/site-packages/rest_framework/views.py", line 506, in dispatch
netbox-1               |     response = handler(request, *args, **kwargs)
netbox-1               |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "/opt/netbox/netbox/extras/api/views.py", line 243, in post
netbox-1               |     script.result = Job.enqueue(
netbox-1               |     ^^^^^^^^^^^^^
netbox-1               | AttributeError: property 'result' of 'Script' object has no setter

Running in the GUI (and getting the correct results):

netbox-worker-1        | 14:41:50 default: extras.scripts.run_script(commit=True, data={'certificate': <SSLCertificate: https://xxxx.xxxx.xxx>}, job=<Job: 14ffa8e8-c81d-4084-bc59-e1ffa36ff47b>, request=<utilities.request.NetBoxFakeRequest object at 0xffff77acbd10>) (14ffa8e8-c81d-4084-bc59-e1ffa36ff47b)
@Leon-Pay Leon-Pay added status: needs triage This issue is awaiting triage by a maintainer type: bug A confirmed report of unexpected behavior in the application labels May 14, 2024
@MalfuncEddie
Copy link

can confirm (related/dup) #16123

@jeremystretch
Copy link
Member

Thank you for submitting this issue, however it appears that this topic has already been raised. Please see issue #16123 for further discussion.

@jeremystretch jeremystretch closed this as not planned Won't fix, can't repro, duplicate, stale May 14, 2024
@jeremystretch jeremystretch added status: duplicate This issue has already been raised and removed status: needs triage This issue is awaiting triage by a maintainer labels May 14, 2024
@bitcollector1
Copy link

works great now! thanks

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: duplicate This issue has already been raised type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

5 participants