Open jsenecal opened 2 weeks ago
@jsenecal would you like to tackle this?
Sure, I can give it a go. You can assign this to me.
I will propose a solution here first before submitting a PR.
It may be sufficient to just catch exceptions on view name resolution when determining related models.
I think catching the exception should be enough. Maybe we can remove the omit
parameter then, as the models are listed explicitly to avoid that exception. Sorry for the inconvenience.
I think catching the exception should be enough. Maybe we can remove the
omit
parameter then, as the models are listed explicitly to avoid that exception. Sorry for the inconvenience.
The exception is generated when Django renders the template. We may need to resolve the view names earlier to see if they exist prior to passing these into the context.
So I've designed two fixes to this:
Use the validated_viewname
filter instead of the viewname
one:
https://github.com/jsenecal/netbox/compare/develop...related_objects-template-fix
Pros: Simple, effective Cons: Not really reusable for other dynamic functionalities in the future
Modify get_related_models
to try to resolve urls at this point and omit the relationship if it cannot be resolved.
https://github.com/jsenecal/netbox/compare/develop...related_objects-utilities-fix
Pros: More targeted fix, allows for reuse of code Cons: Moves a bit more code around
In both cases omit
could be removed everywhere but it does provide some performance improvements for netbox native models.
@jeremystretch let me know which approach you prefer and I'll prepare a proper PR.
@jeremystretch any chance you could look into my proposed fixes?
Deployment Type
Self-hosted
NetBox Version
v4.0.6
Python Version
3.10
Steps to Reproduce
A bit complex, let me know if you really want me to go through a thorough plugin example
_list
views.Expected Behavior
Related core model detail view should work as expected regardless of the missing
_list
view in the plugin.Observed Behavior
Bug Introduced by https://github.com/netbox-community/netbox/commit/5353f837108ee5db11537bc95dde3ce9bc4a042c
I have models with no
*_list
views related to core models in my plugin and they get picked up byget_related_models
inGetRelatedModelsMixin
which raises aNoReverseMatch
exception innetbox/templates/inc/panels/related_objects.html
Technically
get_related_models
has been designed with the idea that one can set theomit
method parameter to an iterable to avoid including these but there does not seem to have API which is exposed to plugin authors for Core models.