Netbox conflicting with Python standard library Lib/secrets.py #3620

Closed
opened 2025-12-29 18:30:12 +01:00 by adam · 3 comments
Owner

Originally created by @diddi- on GitHub (Apr 29, 2020).

Originally assigned to: @steffann on GitHub.

Netbox does not have a single root netbox package so anything inside netbox/ will be considered a separate package in Python. For example the secets package in Netbox conflicts with Python standard library secrets.

Environment

  • Python version: 3.7.7
  • NetBox version: 2.8.1

Steps to Reproduce

  1. Create a new custom script 1-test.py
import secrets
class SecretScript(Script):
    def run(self, data):
        self.log_success(secrets.token_hex())
  1. Browse to the script from web ui http://localhost/extras/scripts/1-test/SecretScript/
  2. Hit Run Script button

Expected Behavior

A success log with the message containing a random hex string, similar to

>>> import secrets
>>> secrets.token_hex()
'95d6e2a2460ffd2fed63d6a78a69ae5a5dd7bf2676e7cd393bc9e80bc261cbe9'

Observed Behavior

Exception:
An exception occurred: AttributeError: module 'secrets' has no attribute 'token_hex'

Originally created by @diddi- on GitHub (Apr 29, 2020). Originally assigned to: @steffann on GitHub. <!-- NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED. This form is only for reproducible bugs. If you need assistance with NetBox installation, or if you have a general question, DO NOT open an issue. Instead, post to our mailing list: https://groups.google.com/forum/#!forum/netbox-discuss Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report, and that any plugins have been disabled. --> Netbox does not have a single root `netbox` package so anything inside `netbox/` will be considered a separate package in Python. For example the `secets` package in Netbox conflicts with Python standard library [`secrets`](https://docs.python.org/3.7/library/secrets.html). ### Environment * Python version: 3.7.7 * NetBox version: 2.8.1 <!-- Describe in detail the exact steps that someone else can take to reproduce this bug using the current stable release of NetBox. Begin with the creation of any necessary database objects and call out every operation being performed explicitly. If reporting a bug in the REST API, be sure to reconstruct the raw HTTP request(s) being made: Don't rely on a client library such as pynetbox. --> ### Steps to Reproduce 1. Create a new custom script `1-test.py` ```from extras.scripts import Script import secrets class SecretScript(Script): def run(self, data): self.log_success(secrets.token_hex()) ``` 2. Browse to the script from web ui `http://localhost/extras/scripts/1-test/SecretScript/` 3. Hit `Run Script` button <!-- What did you expect to happen? --> ### Expected Behavior A `success` log with the message containing a random hex string, similar to ``` >>> import secrets >>> secrets.token_hex() '95d6e2a2460ffd2fed63d6a78a69ae5a5dd7bf2676e7cd393bc9e80bc261cbe9' ``` <!-- What happened instead? --> ### Observed Behavior Exception: ```An exception occurred: AttributeError: module 'secrets' has no attribute 'token_hex'```
adam closed this issue 2025-12-29 18:30:12 +01:00
Author
Owner

@diddi- commented on GitHub (Apr 29, 2020):

I discovered this while trying to build a Python package that our custom scripts will use. Having all directories under netbox/ be their own top level packages make imports a bit awkward as Netbox rely on its own secrets package for example.

Would it be possible to have a structure like netbox.secrets instead?

@diddi- commented on GitHub (Apr 29, 2020): I discovered this while trying to build a Python package that our custom scripts will use. Having all directories under `netbox/` be their own top level packages make imports a bit awkward as Netbox rely on its own `secrets` package for example. Would it be possible to have a structure like `netbox.secrets` instead?
Author
Owner

@jeremystretch commented on GitHub (Apr 29, 2020):

Fun fact: NetBox predates the standard secrets library, which was introduced in Python 3.6. We recently had to work around this conflict to accommodate a recent Django release, which you can see here.

Unfortunately, I'm not sure there's a palatable solution to this problem. We would need to rename the secrets app, which obviously would be quite disruptive and probably not worth the negligible gain.

@jeremystretch commented on GitHub (Apr 29, 2020): Fun fact: NetBox predates the standard `secrets` library, which was introduced in Python 3.6. We recently had to work around this conflict to accommodate a recent Django release, which you can see [here](https://github.com/netbox-community/netbox/commit/f1b042180536092fa99d67f55fe5d5ab280d0f69). Unfortunately, I'm not sure there's a palatable solution to this problem. We would need to rename the `secrets` app, which obviously would be [quite disruptive](https://stackoverflow.com/a/8408131/2694522) and probably not worth the negligible gain.
Author
Owner

@jeremystretch commented on GitHub (May 12, 2020):

I'm going to close this issue as I don't think there's anything actionable in the immediate future. Might be worth revisiting down the road but unless the conflict escalates to a serious problem, renaming the app is unlikely to be worth the disruption to users.

@jeremystretch commented on GitHub (May 12, 2020): I'm going to close this issue as I don't think there's anything actionable in the immediate future. Might be worth revisiting down the road but unless the conflict escalates to a serious problem, renaming the app is unlikely to be worth the disruption to users.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3620