Repository: netbox-community/netbox

Issue:
AttributeError at /api/extras/scripts/8/ can't set attribute 'result'
### Deployment Type

Self-hosted

### NetBox Version

v4.0.1

### Python Version

3.10

### Steps to Reproduce

following:

https://docs.netbox.dev/en/stable/customization/custom-scripts/

 curl -X POST -H "Authorization: Token $MY_TOKEN" -H "Content-Type: application/json" -H "Accept: application/json; indent=4" https://netbox-test/api/extras/scripts/8/ --data '{"da
ta": {"foo": "somevalue", "bar": 123}, "commit": true}'

I get the error 
AttributeError at /api/extras/scripts/8/
can't set attribute 'result'

Additional question: in the past I could run the script with "https://netbox-test/api/extras/scripts/scriptA.class" 
This does not work anymore and I need an ID ;(

```
May 14 11:42:59 netbox-test uwsgi[640883]: Internal Server Error: /api/extras/scripts/8/
May 14 11:42:59 netbox-test uwsgi[640883]: Traceback (most recent call last):
May 14 11:42:59 netbox-test uwsgi[640883]:   File "/netbox/releases/netbox-4.0.1/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
May 14 11:42:59 netbox-test uwsgi[640883]:     response = get_response(request)
May 14 11:42:59 netbox-test uwsgi[640883]:   File "/netbox/releases/netbox-4.0.1/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
May 14 11:42:59 netbox-test uwsgi[640883]:     response = wrapped_callback(request, *callback_args, **callback_kwargs)
May 14 11:42:59 netbox-test uwsgi[640883]:   File "/netbox/releases/netbox-4.0.1/venv/lib/python3.10/site-packages/django/views/decorators/csrf.py", line 65, in _view_wrapper
May 14 11:42:59 netbox-test uwsgi[640883]:     return view_func(request, *args, **kwargs)
May 14 11:42:59 netbox-test uwsgi[640883]:   File "/netbox/releases/netbox-4.0.1/venv/lib/python3.10/site-packages/rest_framework/viewsets.py", line 124, in view
May 14 11:42:59 netbox-test uwsgi[640883]:     return self.dispatch(request, *args, **kwargs)
May 14 11:42:59 netbox-test uwsgi[640883]:   File "/netbox/releases/netbox-4.0.1/venv/lib/python3.10/site-packages/rest_framework/views.py", line 509, in dispatch
May 14 11:42:59 netbox-test uwsgi[640883]:     response = self.handle_exception(exc)
May 14 11:42:59 netbox-test uwsgi[640883]:   File "/netbox/releases/netbox-4.0.1/venv/lib/python3.10/site-packages/rest_framework/views.py", line 469, in handle_exception
May 14 11:42:59 netbox-test uwsgi[640883]:     self.raise_uncaught_exception(exc)
May 14 11:42:59 netbox-test uwsgi[640883]:   File "/netbox/releases/netbox-4.0.1/venv/lib/python3.10/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
May 14 11:42:59 netbox-test uwsgi[640883]:     raise exc
May 14 11:42:59 netbox-test uwsgi[640883]:   File "/netbox/releases/netbox-4.0.1/venv/lib/python3.10/site-packages/rest_framework/views.py", line 506, in dispatch
May 14 11:42:59 netbox-test uwsgi[640883]:     response = handler(request, *args, **kwargs)
May 14 11:42:59 netbox-test uwsgi[640883]:   File "/netbox/releases/netbox-4.0.1/netbox/./extras/api/views.py", line 243, in post
May 14 11:42:59 netbox-test uwsgi[640883]:     script.result = Job.enqueue(
May 14 11:42:59 netbox-test uwsgi[640883]: AttributeError: can't set attribute 'result'
May 14 11:42:59 netbox-test uwsgi[640883]: [pid: 640883|app: 0|req: 43/43] 172.31.68.177 () {60 vars in 1061 bytes} [Tue May 14 11:42:59 2024] POST /api/extras/scripts/8/ => generated 23250 bytes in 54 msecs (HTTP/1.1 500) 10 headers in 378 bytes (1 switches on core 0)
```



PS: upgraded from v3.5.4 -> 3.7.7 -> 4.0.0 -> 4.0.1

### Expected Behavior

script is executed successfully

(via gui it does work

### Observed Behavior

AttributeError: can't set attribute 'result'


```
May 14 11:42:59 netbox-test uwsgi[640883]: Internal Server Error: /api/extras/scripts/8/
May 14 11:42:59 netbox-test uwsgi[640883]: Traceback (most recent call last):
May 14 11:42:59 netbox-test uwsgi[640883]:   File "/netbox/releases/netbox-4.0.1/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
May 14 11:42:59 netbox-test uwsgi[640883]:     response = get_response(request)
May 14 11:42:59 netbox-test uwsgi[640883]:   File "/netbox/releases/netbox-4.0.1/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
May 14 11:42:59 netbox-test uwsgi[640883]:     response = wrapped_callback(request, *callback_args, **callback_kwargs)
May 14 11:42:59 netbox-test uwsgi[640883]:   File "/netbox/releases/netbox-4.0.1/venv/lib/python3.10/site-packages/django/views/decorators/csrf.py", line 65, in _view_wrapper
May 14 11:42:59 netbox-test uwsgi[640883]:     return view_func(request, *args, **kwargs)
May 14 11:42:59 netbox-test uwsgi[640883]:   File "/netbox/releases/netbox-4.0.1/venv/lib/python3.10/site-packages/rest_framework/viewsets.py", line 124, in view
May 14 11:42:59 netbox-test uwsgi[640883]:     return self.dispatch(request, *args, **kwargs)
May 14 11:42:59 netbox-test uwsgi[640883]:   File "/netbox/releases/netbox-4.0.1/venv/lib/python3.10/site-packages/rest_framework/views.py", line 509, in dispatch
May 14 11:42:59 netbox-test uwsgi[640883]:     response = self.handle_exception(exc)
May 14 11:42:59 netbox-test uwsgi[640883]:   File "/netbox/releases/netbox-4.0.1/venv/lib/python3.10/site-packages/rest_framework/views.py", line 469, in handle_exception
May 14 11:42:59 netbox-test uwsgi[640883]:     self.raise_uncaught_exception(exc)
May 14 11:42:59 netbox-test uwsgi[640883]:   File "/netbox/releases/netbox-4.0.1/venv/lib/python3.10/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
May 14 11:42:59 netbox-test uwsgi[640883]:     raise exc
May 14 11:42:59 netbox-test uwsgi[640883]:   File "/netbox/releases/netbox-4.0.1/venv/lib/python3.10/site-packages/rest_framework/views.py", line 506, in dispatch
May 14 11:42:59 netbox-test uwsgi[640883]:     response = handler(request, *args, **kwargs)
May 14 11:42:59 netbox-test uwsgi[640883]:   File "/netbox/releases/netbox-4.0.1/netbox/./extras/api/views.py", line 243, in post
May 14 11:42:59 netbox-test uwsgi[640883]:     script.result = Job.enqueue(
May 14 11:42:59 netbox-test uwsgi[640883]: AttributeError: can't set attribute 'result'
May 14 11:42:59 netbox-test uwsgi[640883]: [pid: 640883|app: 0|req: 43/43] 172.31.68.177 () {60 vars in 1061 bytes} [Tue May 14 11:42:59 2024] POST /api/extras/scripts/8/ => generated 23250 bytes in 54 msecs (HTTP/1.1 500) 10 headers in 378 bytes (1 switches on core 0)
```


Discussion:
Hi,

additional info. Reverted to  v3.5.4  and did the upgrade again

3.7.7  -> works
4.0.1 -> does not work
As provided in #16129 this also breaks the usage of using the script names in the url. And does not reflect in the documentation about custom scripts.

Resolving patch:
diff --git a/netbox/extras/api/views.py b/netbox/extras/api/views.py
--- a/netbox/extras/api/views.py
+++ b/netbox/extras/api/views.py
@@ -240,9 +240,9 @@ def post(self, request, pk):
             raise RQWorkerNotRunningException()
 
         if input_serializer.is_valid():
-            script.result = Job.enqueue(
+            Job.enqueue(
                 run_script,
-                instance=script.module,
+                instance=script,
                 name=script.python_class.class_name,
                 user=request.user,
                 data=input_serializer.data['data'],


Test patch: