Fail gracefully if Custom Link URL does not expand #2833

Closed
opened 2025-12-29 18:22:37 +01:00 by adam · 3 comments
Owner

Originally created by @candlerb on GitHub (Aug 28, 2019).

Originally assigned to: @jeremystretch on GitHub.

Environment

  • Python version: 3.5.2
  • NetBox version: 2.6.2

Proposed Functionality

At the moment, if you define a Custom Link but there is a template expansion failure in the link URL, Netbox raises a full-blown exception instead of displaying the object you requested. Users tend to confuse this with a bug in Netbox (e.g. #3304, forum)

I propose instead: if a template error occurs during expansion of the URL in a Custom Link, display the button greyed out. Preferably include the exception text as a tooltip.

Note: it's also possible that a template error occurs during expansion of the Text in a Custom Link. In that case, I think it's reasonable to continue to raise an exception, but an alternative would be to log the error and suppress the button, as if the text were blank.

Use Case

  • Making custom links easier to use: e.g. you can link to obj.primary_ip4.address.ip without having to worry whether the device has that field defined or not
  • Reducing support queries on the mailing list

Database Changes

None

External Dependencies

None

Originally created by @candlerb on GitHub (Aug 28, 2019). Originally assigned to: @jeremystretch on GitHub. ### Environment * Python version: 3.5.2 * NetBox version: 2.6.2 ### Proposed Functionality At the moment, if you define a Custom Link but there is a template expansion failure in the link URL, Netbox raises a full-blown exception instead of displaying the object you requested. Users tend to confuse this with a bug in Netbox (e.g. #3304, [forum](https://groups.google.com/forum/#!topic/netbox-discuss/m9G3_tUVPkQ)) I propose instead: if a template error occurs during expansion of the URL in a Custom Link, display the button greyed out. Preferably include the exception text as a tooltip. Note: it's also possible that a template error occurs during expansion of the Text in a Custom Link. In that case, I think it's reasonable to continue to raise an exception, but an alternative would be to log the error and suppress the button, as if the text were blank. ### Use Case * Making custom links easier to use: e.g. you can link to `obj.primary_ip4.address.ip` without having to worry whether the device has that field defined or not * Reducing support queries on the mailing list ### Database Changes None ### External Dependencies None
adam added the status: accepted label 2025-12-29 18:22:37 +01:00
adam closed this issue 2025-12-29 18:22:37 +01:00
Author
Owner

@bdlamprecht commented on GitHub (Aug 29, 2019):

Completely agree with this FR. If an object doesn't have a field or attribute used in a custom link, it shouldn't cause the whole page to fail.

I was surprised by this when I tried to manually create a new device and then after I did, I received an error stating that an attribute didn't exist.

Immediately I went to the open / closed issues and found this one and #3299 and the "work around" did solve the problem. My opinion is that it should fail gracefully instead of the failing hard as it currently does, especially for something as common as obj.primary_ip.address.ip.

@bdlamprecht commented on GitHub (Aug 29, 2019): Completely agree with this FR. If an object doesn't have a field or attribute used in a custom link, it shouldn't cause the whole page to fail. I was surprised by this when I tried to manually create a new device and then after I did, I received an error stating that an attribute didn't exist. Immediately I went to the open / closed issues and found this one and #3299 and the "work around" did solve the problem. My opinion is that it should fail gracefully instead of the failing hard as it currently does, especially for something as common as `obj.primary_ip.address.ip`.
Author
Owner

@jeremystretch commented on GitHub (Sep 3, 2019):

Handling the exception gracefully is easy, but reporting the failure to the user needs more thought. Exceptions can occur while rendering either the text or URL of grouped or non-grouped links, and the exception message needs to be conveyed in an obvious yet non-intrusive manner.

@jeremystretch commented on GitHub (Sep 3, 2019): Handling the exception gracefully is easy, but reporting the failure to the user needs more thought. Exceptions can occur while rendering either the text or URL of grouped or non-grouped links, and the exception message needs to be conveyed in an obvious yet non-intrusive manner.
Author
Owner

@candlerb commented on GitHub (Sep 3, 2019):

I believe that putting the text of the exception (without backtrace) in the "title" attribute means it will be displayed as a tooltip in most browsers. It seems modern browsers support "title" atttribute on <option> elements too, so that should deal with grouped links.

I just tested it:

<select>
<option>foo</option>
<option>bar</option>
<option title="Attribute abc missing" disabled>baz</option>
</select>

In Chrome 76, this works as expected: hover over the disabled 'baz' option and you see the message.

For anyone who doesn't have a compatible browser, but still wants to know why a particular selection is disabled, they can always inspect the HTML to read the title attribute.

@candlerb commented on GitHub (Sep 3, 2019): I believe that putting the text of the exception (without backtrace) in the "title" attribute means it will be displayed as a tooltip in most browsers. It seems modern browsers support ["title" atttribute on &lt;option&gt; elements](https://stackoverflow.com/questions/3249591/how-can-i-display-a-tooltip-on-an-html-option-tag) too, so that should deal with grouped links. I just tested it: ``` <select> <option>foo</option> <option>bar</option> <option title="Attribute abc missing" disabled>baz</option> </select> ``` In Chrome 76, this works as expected: hover over the disabled 'baz' option and you see the message. For anyone who doesn't have a compatible browser, but still wants to know why a particular selection is disabled, they can always inspect the HTML to read the title attribute.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2833