[PR #16170] [MERGED] 16145 Use module.ScriptName to call Script API instead of PK #14795

Closed
opened 2025-12-29 23:26:47 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/16170
Author: @arthanson
Created: 5/17/2024
Status: Merged
Merged: 5/22/2024
Merged by: @jeremystretch

Base: developHead: 16145-script


📝 Commits (5)

  • b67b4f6 16145 script api use module.script name instead of pk
  • 452ba22 16145 fix test
  • 754ab82 16145 allow both pk and script name
  • 1253d91 16145 update doc string
  • 1d5d283 Simplify retrieval logic

📊 Changes

1 file changed (+16 additions, -4 deletions)

View changed files

📝 netbox/extras/api/views.py (+16 -4)

📄 Description

Fixes: #16145

Changes the script api back to using the "module.ScriptName" instead of id (this is the way it was in NB3.x). The test was a bit of a mess to fix, the issue is the get_vars function in the Script class calls the python_class property which calls module_scripts on on the module - this tries to load the module which fails as the script doesn't actually exist on disk.

curl -X 'GET' \
  'http://localhost:8000/api/extras/scripts/testscript.NewBranchScript/' \
  -H 'accept: application/json; indent=4' \
  -H 'Content-Type: application/json' \
  -H "Authorization: Token 6f22af1129a164f92e4abdfa716cb54df9684f5e"

{
    "id": 3,
    "url": "http://localhost:8000/api/extras/scripts/3/",
    "module": 7,
    "name": "NewBranchScript",
    "description": "Provision a new branch site",
    "vars": {
        "site_name": "StringVar",
        "switch_count": "IntegerVar",
        "switch_model": "ObjectVar",
        "manufacturer": "ObjectVar"
    },
    "result": {
        "object_id": null,
        "name": "",
        "scheduled": null,
        "interval": null,
        "started": null,
        "completed": null,
        "data": null,
        "job_id": null
    },
    "display": "NewBranchScript (testscript)",
    "is_executable": true
}

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/16170 **Author:** [@arthanson](https://github.com/arthanson) **Created:** 5/17/2024 **Status:** ✅ Merged **Merged:** 5/22/2024 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `develop` ← **Head:** `16145-script` --- ### 📝 Commits (5) - [`b67b4f6`](https://github.com/netbox-community/netbox/commit/b67b4f66da8136e0b0f8c54782622c54312c491d) 16145 script api use module.script name instead of pk - [`452ba22`](https://github.com/netbox-community/netbox/commit/452ba22bd8f903a083d7812284ebfcf8a35f32b8) 16145 fix test - [`754ab82`](https://github.com/netbox-community/netbox/commit/754ab82a99009953b9ed25dd017a904ecf7d15b7) 16145 allow both pk and script name - [`1253d91`](https://github.com/netbox-community/netbox/commit/1253d9188fdcf39d7995fab9d172b99d959d69f3) 16145 update doc string - [`1d5d283`](https://github.com/netbox-community/netbox/commit/1d5d283cb979a0aae2ece1baa09e01a1b352186c) Simplify retrieval logic ### 📊 Changes **1 file changed** (+16 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `netbox/extras/api/views.py` (+16 -4) </details> ### 📄 Description ### Fixes: #16145 Changes the script api back to using the "module.ScriptName" instead of id (this is the way it was in NB3.x). The test was a bit of a mess to fix, the issue is the get_vars function in the Script class calls the python_class property which calls module_scripts on on the module - this tries to load the module which fails as the script doesn't actually exist on disk. ``` curl -X 'GET' \ 'http://localhost:8000/api/extras/scripts/testscript.NewBranchScript/' \ -H 'accept: application/json; indent=4' \ -H 'Content-Type: application/json' \ -H "Authorization: Token 6f22af1129a164f92e4abdfa716cb54df9684f5e" { "id": 3, "url": "http://localhost:8000/api/extras/scripts/3/", "module": 7, "name": "NewBranchScript", "description": "Provision a new branch site", "vars": { "site_name": "StringVar", "switch_count": "IntegerVar", "switch_model": "ObjectVar", "manufacturer": "ObjectVar" }, "result": { "object_id": null, "name": "", "scheduled": null, "interval": null, "started": null, "completed": null, "data": null, "job_id": null }, "display": "NewBranchScript (testscript)", "is_executable": true } ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 23:26:47 +01:00
adam closed this issue 2025-12-29 23:26:47 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#14795