-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Search fails due to search cache populated with non-existent models after plugin removal ('NoneType' object has no attribute 'objects') #13507
Comments
Here's some analysis based on my conversation with @kkthxbye-code on Slack and a workaround that got me out of this condition: The pre-condition seems to be that a plugin (in my case, (netbox-topology-views)[https://github.com/mattieserver/netbox-topology-views] has been installed, and has populated some data into the database. Specifically in my case, there were some "coordinates" (i.e. on a topology graph, not lat/lng) that were set on a device. After the plugin was uninstalled, a search on the name of the object with coordinates associated with it would error out with this message: 'NoneType' object has no attribute 'objects' By running this with DEBUG on, I was able to repro that this crashes on this line: https://github.com/netbox-community/netbox/blob/v3.5.8/netbox/utilities/fields.py#L117 The exception seems to be hit because In trying to fix this problem on my system, I first tried just dropping all the tables relating to netbox_topology_views from Postgres, but that wasn't enough. With the help of @kkthxbye-code, we were able to identify that the problem was that, in addition to stale data still existing in the database (which I had previously manually removed), cached data related to this was still present in the We expected that rebuilding the search index using From my analysis there's at least few places where this could be addressed and my initial thoughts for how to address this:
|
Oh by the way, I've saved a copy of the database that is corrupted in this state, so in case the proposed repro doesn't quite work out, that data will be available for more investigation. However I'm not comfortable sharing this SQL dump because it contains confidential information. |
For anyone else running into this, until there's a code fix for this, here's how you can completely re-build the search index from scratch. That should clear this issue up. However, as for any time you're working with nbshell and and working at this level, and especially when running commands posted by some random guy on the Internet, make sure you have a full backup of your system, in case something goes off the rails.
This has worked for me and for one other person who's had this issue. |
FYI: I've written up a fix for the missing "None" check (and I found a second one as well) but due to project rules I won't be able to open a real PR until this has been accepted, so I've opened it as a draft PR. |
Replicates fine, thank you for the thorough report. My steps:
This issue is similar to #11335 - fixed by #11709 and #13117 I'm not sure your draft PR fixes the underlying issue and trying it out quick doesn't fix it, but does move the issue to another method. Maybe @jeremystretch or @abhi1693 can have a look, I'm not really that familiar with the custom code we have for gfk lookups. |
Depends what you mean is the underlying issue, in my opinion there are at least two underlying issues:
Cleaning up the search cache will address 1, and adding checks for "None" will address 2, it's possible your repro is slightly different than the one I ran into myself, because my fix "works for me". But I did a quick code search before and I found a lot of cases of the pattern of just calling get_model() on a contenttype and expecting it to work, so it's possible that I might have missed a code path. In my opinion it should be fixed on both ends. |
Are you missing a repro step here, did you not need to uninstall the plugin? |
Just missed the last step, added it now, thanks. |
This fix worked for me but I've not had the time to restore the old DB and try to narrow down the culprit with DEBUG. That said it looks like you fine folks have a good grasp on this issue. I just wanted to say thanks again to @pv2b for the fix as it was annoying me for months! |
NetBox version
v3.5.8
Python version
Steps to Reproduce
Note: The full and exact repro steps aren't verified right now, but I agreed with @kkthxbye-code that I should file this as a bug anyway, as per our discussion on Slack.
Expected Behavior
I expect to get a page of search results including that object.
Observed Behavior
I an get error screen with the python exception 'NoneType' object has no attribute 'objects'
The text was updated successfully, but these errors were encountered: