Cannot resolve keyword 'tenant' into field when opening Tenant page #16956
Replies: 1 comment 1 reply
-
This comes from netbox/utilities/relations.py Calling this function, it gets a list of all models which have a FK relationship to Tenant - and it even returns the name of the field which contains that relationship, i.e. it's a list of tuples of Then deep inside Netbox tenancy views you found a buried, hard-coded assumption that any model which has a FK relationship to Tenant maintains that via an attribute called However, that code does not exist in Netbox v4.0.7, and it looks like it was completely rewritten in around v4.0.6:
The new filtering logic from GetRelatedModelsMixin is here. So you could try updating to latest Netbox v4.0.7 and see if the problem goes away. (I've not tested it myself). If you can't do that, I think you'll have to go with the flow and change your relationship name to |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello guys!
I'm updating my Netbox from 3.4.7 to 3.7.8 in my local environment and I'm having a problem.
I have several custom plugins, and one of them have models that have FK to the Netbox Tenant model.
After the update the Tenant page is returning me this error (I removed this specific custom plugin and everything is working as expected, so I was able to narrow down the problem to this specific plugin):
My model is like this:
Prior to that error I was having:
But then I added
objects = RestrictedQuerySet.as_manager()
to the model and the error was solved, but then the FieldError showed up.I changed the name of my
project
field totenant
, ran the migration and the error stopped. But changing the model name will be a big refactor on my integrations, so any help here will be appreciated.Am I missing something here or I really need to change the name of my field? If thats the case, why I need to do this? Is there anything else that I can do to avoid changing the name of the field?
Thanks!
EDIT:
I understood why its happening, in the
TenantView
we have theget_extra_context()
method that is getting all related models to Tenant.When the
for
reaches my custom plugin model, it is breaking in the query:model.objects.restrict(request.user, 'view').filter(tenant=instance)
because the first part of the querymodel.objects.restrict(request.user, 'view')
is returning a RestrictedQuerySet of my CustomScript objects, and when it tries tofilter(tenant=instance)
my model don't have tenant as a field.But even with that I'm still looking to see if anyone knows something that can help to avoid changing the name of the field. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions