[PR #18127] [MERGED] Closes 18061: Hide traceback from rendered device config #15277

Closed
opened 2025-12-30 00:21:02 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/18127
Author: @alehaa
Created: 11/30/2024
Status: Merged
Merged: 12/11/2024
Merged by: @jeremystretch

Base: developHead: 18061-hide-traceback


📝 Commits (2)

  • 4cb6abf Hide traceback from rendered device config
  • c2d429f Improve error message display; replicate changes for VMs

📊 Changes

4 files changed (+52 additions, -34 deletions)

View changed files

📝 netbox/dcim/views.py (+5 -5)
📝 netbox/templates/dcim/device/render_config.html (+21 -12)
📝 netbox/templates/virtualization/virtualmachine/render_config.html (+21 -12)
📝 netbox/virtualization/views.py (+5 -5)

📄 Description

Fixes: #18061

When an exception occurs during device configuration rendering, it usually doesn't contain information about the template being rendered, but rather the trace of how the template was rendered. Since this could confuse users and expose internal server information, it is now hidden.

Before:

Traceback (most recent call last):
  File "/opt/netbox/netbox/dcim/views.py", line 2129, in get_extra_context
    rendered_config = config_template.render(context=context_data)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/netbox/extras/models/configs.py", line 282, in render
    output = template.render(**_context)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/venv/lib/python3.12/site-packages/jinja2/environment.py", line 1304, in render
    self.environment.handle_exception()
  File "/opt/netbox/venv/lib/python3.12/site-packages/jinja2/environment.py", line 939, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 1, in top-level template code
  File "/opt/netbox/venv/lib/python3.12/site-packages/jinja2/sandbox.py", line 327, in getattr
    value = getattr(obj, attribute)
            ^^^^^^^^^^^^^^^^^^^^^^^
jinja2.exceptions.UndefinedError: 'dcim.models.devices.Device object' has no attribute 'next'

After:

An error occurred while rendering the template: 'dcim.models.devices.Device object' has no attribute 'next'

This is the same message as displayed in the message notification.


🔄 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/18127 **Author:** [@alehaa](https://github.com/alehaa) **Created:** 11/30/2024 **Status:** ✅ Merged **Merged:** 12/11/2024 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `develop` ← **Head:** `18061-hide-traceback` --- ### 📝 Commits (2) - [`4cb6abf`](https://github.com/netbox-community/netbox/commit/4cb6abfc18cbfbe903775881f24fa1f7415a3d1e) Hide traceback from rendered device config - [`c2d429f`](https://github.com/netbox-community/netbox/commit/c2d429f4d82a07094d8ce33b8eb2c30e62fe4889) Improve error message display; replicate changes for VMs ### 📊 Changes **4 files changed** (+52 additions, -34 deletions) <details> <summary>View changed files</summary> 📝 `netbox/dcim/views.py` (+5 -5) 📝 `netbox/templates/dcim/device/render_config.html` (+21 -12) 📝 `netbox/templates/virtualization/virtualmachine/render_config.html` (+21 -12) 📝 `netbox/virtualization/views.py` (+5 -5) </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 approved and assigned prior to opening a pull request. This helps avoid waste time and effort on a proposed change that we might not be able to accept. IF YOUR PULL REQUEST DOES NOT REFERENCE AN ISSUE WHICH HAS BEEN ASSIGNED TO YOU, IT WILL BE CLOSED AUTOMATICALLY. Please specify your assigned issue number on the line below. --> ### Fixes: #18061 <!-- Please include a summary of the proposed changes below. --> When an exception occurs during device configuration rendering, it usually doesn't contain information about the template being rendered, but rather the trace of **how** the template was rendered. Since this could confuse users and expose internal server information, it is now hidden. #### Before: ``` Traceback (most recent call last): File "/opt/netbox/netbox/dcim/views.py", line 2129, in get_extra_context rendered_config = config_template.render(context=context_data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/netbox/extras/models/configs.py", line 282, in render output = template.render(**_context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/venv/lib/python3.12/site-packages/jinja2/environment.py", line 1304, in render self.environment.handle_exception() File "/opt/netbox/venv/lib/python3.12/site-packages/jinja2/environment.py", line 939, in handle_exception raise rewrite_traceback_stack(source=source) File "<template>", line 1, in top-level template code File "/opt/netbox/venv/lib/python3.12/site-packages/jinja2/sandbox.py", line 327, in getattr value = getattr(obj, attribute) ^^^^^^^^^^^^^^^^^^^^^^^ jinja2.exceptions.UndefinedError: 'dcim.models.devices.Device object' has no attribute 'next' ``` #### After: ``` An error occurred while rendering the template: 'dcim.models.devices.Device object' has no attribute 'next' ``` This is the same message as displayed in the message notification. --- <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-30 00:21:02 +01:00
adam closed this issue 2025-12-30 00:21:02 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#15277