Closes: #540 - Clarify Django bootstrap for portable schema export scripts#541
Closes: #540 - Clarify Django bootstrap for portable schema export scripts#541bctiemann wants to merge 2 commits into
Conversation
…rt scripts Users running export_cots() in a plain .py file hit AppRegistryNotReady because django.setup() is never called. Add Option A (manage.py nbshell) and Option B (standalone script with django.setup()) to the Exporting a Schema section, plus an admonition explaining the error. Addresses discussion #534. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
pheus
left a comment
There was a problem hiding this comment.
This is a useful docs improvement, but I don’t think we should merge the examples in their current form.
The current commands do not make it clear that they need to run in NetBox’s virtualenv. That’s an important detail for this type of documentation: users copying these examples with the system Python may hit import errors or dependency mismatches that look like issues with the export code itself.
We should also avoid presenting /opt/netbox as though it is the required installation path. It is a common example, but NetBox can be installed in other locations.
Please update the examples so they:
- Treat
/opt/netboxas an example NetBox installation root. - Activate NetBox’s virtualenv, or otherwise use the virtualenv Python.
- Make clear that
/path/to/export_cot.pyis just the user’s script path.
For example:
# Replace this with your NetBox installation root.
export NETBOX_ROOT=/opt/netbox
source "$NETBOX_ROOT/venv/bin/activate"
cd "$NETBOX_ROOT"
PYTHONPATH="$NETBOX_ROOT/netbox" python3 /path/to/export_cot.pyWith that clarified, the overall structure of the new section looks good.
… examples - Use NETBOX_ROOT variable throughout so /opt/netbox is clearly an example - Show venv activation in Option 2 bash invocation - Clarify /path/to/export_cot.py is the user script, not a fixed path - Add full-schema (all COTs) export snippet alongside the filtered example Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
bctiemann
left a comment
There was a problem hiding this comment.
Thanks for the clear feedback, Martin. Updated in 88c7891:
- Introduced a
NETBOX_ROOTvariable in both Option 1 and Option 2 so/opt/netboxis explicitly labelled as an example, not a required path. - Option 2 now shows
source "$NETBOX_ROOT/venv/bin/activate"before running the script, using your suggested bash snippet. - Clarified that
/path/to/export_cot.pyis the user's script ("Where/path/to/export_cot.pyis your script, containing:"). - Also folded in cleboo's suggestion from the issue: an all-COTs export snippet sits alongside the filtered one in Option 1.
Closes: #540
Summary
manage.py nbshell(zero setup, recommended) and a standalone.pyscript that callsdjango.setup()before any imports.AppRegistryNotReadyerror so users who encounter it have an immediate explanation and fix.Addresses user report in discussion #534.
Test plan
mkdocs servepython export_cot.pyfrom/opt/netbox/netbox/