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

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

Closed
diddi- opened this issue Apr 29, 2020 · 3 comments
Closed

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

diddi- opened this issue Apr 29, 2020 · 3 comments
Assignees

Comments

@diddi-
Copy link

diddi- commented Apr 29, 2020

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'

@diddi-
Copy link
Author

diddi- commented 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?

@jeremystretch
Copy link
Member

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
Copy link
Member

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.

@steffann steffann self-assigned this May 13, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants