Просмотр исходного кода

Fixes #12144: Ensure consistent treatment of context data when rendering config templates via UI & API

jeremystretch 2 лет назад
Родитель
Сommit
2805633b16
3 измененных файлов с 9 добавлено и 6 удалено
  1. 1 0
      docs/release-notes/version-3.5.md
  2. 6 2
      netbox/dcim/api/views.py
  3. 2 4
      netbox/dcim/views.py

+ 1 - 0
docs/release-notes/version-3.5.md

@@ -77,6 +77,7 @@ Two new webhook trigger events have been introduced: `job_start` and `job_end`.
 * [#12109](https://github.com/netbox-community/netbox/issues/12109) - Fix migration error when replicating more than 100 job results
 * [#12112](https://github.com/netbox-community/netbox/issues/12112) - Do not link data source URL for local paths
 * [#12115](https://github.com/netbox-community/netbox/issues/12115) - Fix rendering config templates from a data file
+* [#12144](https://github.com/netbox-community/netbox/issues/12144) - Ensure consistent treatment of context data when rendering config templates via UI & API
 * [#12146](https://github.com/netbox-community/netbox/issues/12146) - Do not display object selector for disabled fields
 
 ### Other Changes

+ 6 - 2
netbox/dcim/api/views.py

@@ -423,9 +423,13 @@ class DeviceViewSet(ConfigContextQuerySetMixin, ConfigTemplateRenderMixin, NetBo
         configtemplate = device.get_config_template()
         if not configtemplate:
             return Response({'error': 'No config template found for this device.'}, status=HTTP_400_BAD_REQUEST)
-        context = {**request.data, 'device': device}
 
-        return self.render_configtemplate(request, configtemplate, context)
+        # Compile context data
+        context_data = device.get_config_context()
+        context_data.update(request.data)
+        context_data.update({'device': device})
+
+        return self.render_configtemplate(request, configtemplate, context_data)
 
 
 class VirtualDeviceContextViewSet(NetBoxModelViewSet):

+ 2 - 4
netbox/dcim/views.py

@@ -2010,10 +2010,8 @@ class DeviceRenderConfigView(generic.ObjectView):
 
     def get_extra_context(self, request, instance):
         # Compile context data
-        context_data = {
-            'device': instance,
-        }
-        context_data.update(**instance.get_config_context())
+        context_data = instance.get_config_context()
+        context_data.update({'device': instance})
 
         # Render the config template
         rendered_config = None