[PR #5266] [MERGED] 4559 config context rendering #12992

Closed
opened 2025-12-29 22:24:46 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/5266
Author: @lampwins
Created: 10/26/2020
Status: Merged
Merged: 10/30/2020
Merged by: @jeremystretch

Base: developHead: 4559-config-context-rendering


📝 Commits (9)

  • 3ba1863 initial work on config context performance improvements
  • 22d2289 add support for regions and vms
  • 82f5d00 account for null value annotations
  • 9e84e3b added tests
  • 26ff33c pep8
  • 606b015 Merge branch 'develop' into 4559-config-context-rendering
  • 047f03a clean up imports
  • db87a69 convert region fields to f-string
  • 28c17f3 move get_queryset() to common mixin

📊 Changes

11 files changed (+416 additions, -15 deletions)

View changed files

📝 netbox/dcim/api/views.py (+2 -2)
📝 netbox/dcim/models/devices.py (+2 -1)
📝 netbox/dcim/views.py (+1 -1)
📝 netbox/extras/api/views.py (+23 -0)
📝 netbox/extras/models/models.py (+10 -2)
📝 netbox/extras/querysets.py (+76 -3)
📝 netbox/extras/tests/test_models.py (+277 -2)
📝 netbox/utilities/query_functions.py (+20 -0)
📝 netbox/virtualization/api/views.py (+2 -2)
📝 netbox/virtualization/models.py (+2 -1)
📝 netbox/virtualization/views.py (+1 -1)

📄 Description

Fixes: #4559

This implements a new queryset manager for the device and virtual machine models which includes an annotate_config_context_data() method. This method uses a dynamically generated subquery with the JSONBAgg function to annotate the list of config context json objects directly on the device and virtual machine querysets.

There are a couple of things to note:

  • Django has included the postgres JSONBAgg function for a while but in 3.2 it includes support for aggregation ordering. My implementation includes a custom subclass which implements the same until we move to 3.2. Ordering is a critical component of being able to do this as a subquery.
  • The original get_for_object() method is still present and actively used. This is still needed to query for the actual ConfigContext instances for a given object, and in certain cases where the annotation is not available.
  • Because the annotation method is optional and not added to the queryset by default, the existing ability to exclude config context data from the API response is still in place.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/5266 **Author:** [@lampwins](https://github.com/lampwins) **Created:** 10/26/2020 **Status:** ✅ Merged **Merged:** 10/30/2020 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `develop` ← **Head:** `4559-config-context-rendering` --- ### 📝 Commits (9) - [`3ba1863`](https://github.com/netbox-community/netbox/commit/3ba18633de14522e48dd9ac50c27ad308a18bb7c) initial work on config context performance improvements - [`22d2289`](https://github.com/netbox-community/netbox/commit/22d2289ed2b809f9e676d8966fa99aa6268b150e) add support for regions and vms - [`82f5d00`](https://github.com/netbox-community/netbox/commit/82f5d0070e2d97672b7b27937da094b5c90fa811) account for null value annotations - [`9e84e3b`](https://github.com/netbox-community/netbox/commit/9e84e3b83bddc796f5031aa3888bcd4bab585291) added tests - [`26ff33c`](https://github.com/netbox-community/netbox/commit/26ff33c41a228db42f42d091c13d7159f039d56d) pep8 - [`606b015`](https://github.com/netbox-community/netbox/commit/606b0153142e8ac152e5dcbbe230bd82f7d2da94) Merge branch 'develop' into 4559-config-context-rendering - [`047f03a`](https://github.com/netbox-community/netbox/commit/047f03a58c085b736f243e4a1d801dec5864dc7a) clean up imports - [`db87a69`](https://github.com/netbox-community/netbox/commit/db87a694884dca4eca214018b6ca1211ea3f1c76) convert region fields to f-string - [`28c17f3`](https://github.com/netbox-community/netbox/commit/28c17f33ab398f20f6c62644ccf9a3ac98cad5d1) move get_queryset() to common mixin ### 📊 Changes **11 files changed** (+416 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `netbox/dcim/api/views.py` (+2 -2) 📝 `netbox/dcim/models/devices.py` (+2 -1) 📝 `netbox/dcim/views.py` (+1 -1) 📝 `netbox/extras/api/views.py` (+23 -0) 📝 `netbox/extras/models/models.py` (+10 -2) 📝 `netbox/extras/querysets.py` (+76 -3) 📝 `netbox/extras/tests/test_models.py` (+277 -2) 📝 `netbox/utilities/query_functions.py` (+20 -0) 📝 `netbox/virtualization/api/views.py` (+2 -2) 📝 `netbox/virtualization/models.py` (+2 -1) 📝 `netbox/virtualization/views.py` (+1 -1) </details> ### 📄 Description <!-- Thank you for your interest in contributing to NetBox! Please note that our contribution policy requires that a feature request or bug report be opened for approval prior to filing a pull request. This helps avoid wasting time and effort on something that we might not be able to accept. Please indicate the relevant feature request or bug report below. IF YOUR PULL REQUEST DOES NOT REFERENCE AN ACCEPTED BUG REPORT OR FEATURE REQUEST, IT WILL BE MARKED AS INVALID AND CLOSED. --> ### Fixes: #4559 This implements a new queryset manager for the device and virtual machine models which includes an `annotate_config_context_data()` method. This method uses a dynamically generated subquery with the `JSONBAgg` function to annotate the list of config context json objects directly on the device and virtual machine querysets. There are a couple of things to note: - Django has included the postgres `JSONBAgg` function for a while but in 3.2 it includes support for aggregation ordering. My implementation includes a custom subclass which implements the same until we move to 3.2. Ordering is a critical component of being able to do this as a subquery. - The original `get_for_object()` method is still present and actively used. This is still needed to query for the actual `ConfigContext` instances for a given object, and in certain cases where the annotation is not available. - Because the annotation method is optional and not added to the queryset by default, the existing ability to exclude config context data from the API response is still in place. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 22:24:46 +01:00
adam closed this issue 2025-12-29 22:24:46 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#12992