Skip to content

Closes: #540 - Clarify Django bootstrap for portable schema export scripts#541

Open
bctiemann wants to merge 2 commits into
mainfrom
534-docs-portable-schema-django-setup
Open

Closes: #540 - Clarify Django bootstrap for portable schema export scripts#541
bctiemann wants to merge 2 commits into
mainfrom
534-docs-portable-schema-django-setup

Conversation

@bctiemann
Copy link
Copy Markdown
Contributor

@bctiemann bctiemann commented May 28, 2026

Closes: #540

Summary

  • Expands the Exporting a Schema section with two explicit usage paths: manage.py nbshell (zero setup, recommended) and a standalone .py script that calls django.setup() before any imports.
  • Adds an admonition explaining the AppRegistryNotReady error so users who encounter it have an immediate explanation and fix.

Addresses user report in discussion #534.

Test plan

  • Docs render correctly via mkdocs serve
  • Option B snippet works when run as python export_cot.py from /opt/netbox/netbox/

…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>
@bctiemann bctiemann changed the title docs: clarify Django bootstrap for portable schema export scripts Closes: #540 - Clarify Django bootstrap for portable schema export scripts May 28, 2026
@bctiemann bctiemann requested review from a team and pheus and removed request for a team May 28, 2026 23:50
Copy link
Copy Markdown
Contributor

@pheus pheus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Treat /opt/netbox as an example NetBox installation root.
  2. Activate NetBox’s virtualenv, or otherwise use the virtualenv Python.
  3. Make clear that /path/to/export_cot.py is 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.py

With 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>
Copy link
Copy Markdown
Contributor Author

@bctiemann bctiemann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clear feedback, Martin. Updated in 88c7891:

  • Introduced a NETBOX_ROOT variable in both Option 1 and Option 2 so /opt/netbox is 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.py is the user's script ("Where /path/to/export_cot.py is 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docs: Portable schema exporter example is missing Django bootstrap steps

2 participants