Fixes #21173: Fix plugin menu registration order timing issue #505

Closed
opened 2026-04-05 16:37:59 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @adionit7 on 1/21/2026

Fixes #21173: Fix plugin menu registration order timing issue

Summary

This PR fixes an issue where plugin menus registered later in the Django app initialization process were not appearing in the NetBox navigation sidebar. The problem occurred because the MENUS list was built at module import time, before all plugins had completed their ready() methods.

Problem

When multiple plugins register menus via navigation.py and PluginConfig.ready(), only the first few plugins' menus would appear in the navigation sidebar. The missing menus were properly registered in the plugin registry, but were not included in the final MENUS list.

Root Cause:

  • netbox/navigation/menu.py was imported during Django startup (in settings.py)
  • At import time, the MENUS list was built by iterating over registry['plugins']['menus']
  • However, only the first few plugins had completed their ready() methods at that point
  • Later plugins' menus were registered after MENUS was already built, so they were excluded

Solution

Converted the static MENUS list to a dynamic get_menus() function that builds the menu list on-demand at request time (when the navigation template tag is rendered). This ensures all plugins have completed their ready() methods before the menus are assembled.

Changes Made:

  • Replaced static MENUS list with get_menus() function in netbox/navigation/menu.py
  • Updated netbox/utilities/templatetags/navigation.py to call get_menus() instead of importing MENUS
  • Function builds the same menu structure, just dynamically at request time

Impact

  • Fixed: All plugin menus now appear in the navigation sidebar regardless of plugin load order
  • Backward Compatible: No changes to plugin registration API or menu structure
  • Performance: Negligible impact - building menu list is microseconds per request
  • No Breaking Changes: Function returns the same list structure as before

Testing

  • Verified that all plugin menus appear in navigation sidebar
  • Confirmed existing plugin menu registration continues to work
  • No changes required to plugin code - existing plugins work without modification
*Originally created by @adionit7 on 1/21/2026* Fixes #21173: Fix plugin menu registration order timing issue ## Summary This PR fixes an issue where plugin menus registered later in the Django app initialization process were not appearing in the NetBox navigation sidebar. The problem occurred because the `MENUS` list was built at module import time, before all plugins had completed their `ready()` methods. ## Problem When multiple plugins register menus via `navigation.py` and `PluginConfig.ready()`, only the first few plugins' menus would appear in the navigation sidebar. The missing menus were properly registered in the plugin registry, but were not included in the final `MENUS` list. **Root Cause:** - `netbox/navigation/menu.py` was imported during Django startup (in `settings.py`) - At import time, the `MENUS` list was built by iterating over `registry['plugins']['menus']` - However, only the first few plugins had completed their `ready()` methods at that point - Later plugins' menus were registered after `MENUS` was already built, so they were excluded ## Solution Converted the static `MENUS` list to a dynamic `get_menus()` function that builds the menu list on-demand at request time (when the navigation template tag is rendered). This ensures all plugins have completed their `ready()` methods before the menus are assembled. **Changes Made:** - Replaced static `MENUS` list with `get_menus()` function in `netbox/navigation/menu.py` - Updated `netbox/utilities/templatetags/navigation.py` to call `get_menus()` instead of importing `MENUS` - Function builds the same menu structure, just dynamically at request time ## Impact - **Fixed:** All plugin menus now appear in the navigation sidebar regardless of plugin load order - **Backward Compatible:** No changes to plugin registration API or menu structure - **Performance:** Negligible impact - building menu list is microseconds per request - **No Breaking Changes:** Function returns the same list structure as before ## Testing - Verified that all plugin menus appear in navigation sidebar - Confirmed existing plugin menu registration continues to work - No changes required to plugin code - existing plugins work without modification
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/netbox#505