Template tags do not take into account plugins #4637

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

Originally created by @DanSheps on GitHub (Mar 8, 2021).

Originally assigned to: @DanSheps on GitHub.

Proposed Changes

Wrap reverse() in try/catch statement to test against both plugins and base namespace.

Justification

Currently, these button tags do not test against the plugins namespace. This would add testing against the namespace with and preserve the original.

Sample code:

    try:
        url = reverse(viewname, kwargs={'pk': instance.pk})
    except NoReverseMatch as e:
        try:
            url = reverse(f'plugins:{viewname}', kwargs={'pk': instance.pk})
        except NoReverseMatch:
            raise NoReverseMatch(e)
Originally created by @DanSheps on GitHub (Mar 8, 2021). Originally assigned to: @DanSheps on GitHub. ### Proposed Changes Wrap reverse() in try/catch statement to test against both plugins and base namespace. ### Justification Currently, these button tags do not test against the plugins namespace. This would add testing against the namespace with and preserve the original. Sample code: ``` try: url = reverse(viewname, kwargs={'pk': instance.pk}) except NoReverseMatch as e: try: url = reverse(f'plugins:{viewname}', kwargs={'pk': instance.pk}) except NoReverseMatch: raise NoReverseMatch(e) ```
adam added the status: under reviewtype: housekeeping labels 2025-12-29 19:18:56 +01:00
adam closed this issue 2025-12-29 19:18:56 +01:00
Author
Owner

@jeremystretch commented on GitHub (Mar 11, 2021):

I don't follow. Can you point to an example where this is breaking something in NetBox? IMO it's bad practice to try and "brute force" the URL resolution: The tag should know when it's being called what URL it intends to resolve.

@jeremystretch commented on GitHub (Mar 11, 2021): I don't follow. Can you point to an example where this is breaking something in NetBox? IMO it's bad practice to try and "brute force" the URL resolution: The tag should know when it's being called what URL it intends to resolve.
Author
Owner

@DanSheps commented on GitHub (Mar 11, 2021):

An example would be ButtonColumn where you resolve the URL automatically for edit/delete/changelog, the button does not take into account the fact that a URL might be in a sub-namespace (plugins:xxx for example) as the resolution is simply f'{model._meta.app_label}:{model._meta.model_name}_{action}'

The try: except: is not the final version now, it has been changed slightly to be a little more sane.

@DanSheps commented on GitHub (Mar 11, 2021): An example would be ButtonColumn where you resolve the URL automatically for edit/delete/changelog, the button does not take into account the fact that a URL might be in a sub-namespace (plugins:xxx for example) as the resolution is simply `f'{model._meta.app_label}:{model._meta.model_name}_{action}'` The try: except: is not the final version now, it has been changed slightly to be a little more sane.
Author
Owner

@jeremystretch commented on GitHub (Mar 17, 2021):

These tags aren't intended for use within plugins, so we don't check the plugins space. Supporting the use of these internal components within a plugin is a much greater undertaking, involving formally extending the plugins API and documenting their usage.

@jeremystretch commented on GitHub (Mar 17, 2021): These tags aren't intended for use within plugins, so we don't check the plugins space. Supporting the use of these internal components within a plugin is a much greater undertaking, involving formally extending the plugins API and documenting their usage.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4637