Skip to content
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 broken (for devices)... 'NoneType' object has no attribute '_base_manager' #16092

Closed
Azmodeszer opened this issue May 11, 2024 · 11 comments

Comments

@Azmodeszer
Copy link
Contributor

Azmodeszer commented May 11, 2024

Deployment Type

Self-hosted

NetBox Version

v4.0.1

Python Version

3.10

Steps to Reproduce

  1. Search for a string that should yield a result in the database

Expected Behavior

Well, you know...

Observed Behavior

<class 'AttributeError'>

'NoneType' object has no attribute '_base_manager'

Seems to only apply if the matching results contain objects of type device.

@Azmodeszer Azmodeszer added status: needs triage This issue is awaiting triage by a maintainer type: bug A confirmed report of unexpected behavior in the application labels May 11, 2024
@Azmodeszer Azmodeszer changed the title Search broken... 'NoneType' object has no attribute '_base_manager' Search broken (for devices)... 'NoneType' object has no attribute '_base_manager' May 11, 2024
@PaulR282
Copy link

Having the same issue, but only certain searches throw this exception, it works most of the time for me.

@jeffgdotorg
Copy link
Collaborator

I've been unable to reproduce this problem on a fresh 4.0.1 installation with a bare minimum object population consisting of:

  • One device role
  • One manufacturer
  • One device type
  • One site
  • One device

I tried several different searches which either do or do not match the solitary device, including some that match the device type and the device.

If you're able to find a full stack trace in the logs, it might provide hints about which kinds of objects are implicated. One way or another, we need to be able to reproduce the problem on a clean system before we can confirm a bug.

@jeffgdotorg jeffgdotorg added the status: revisions needed This issue requires additional information to be actionable label May 13, 2024
@PaulR282
Copy link

If you're able to find a full stack trace in the logs, it might provide hints about which kinds of objects are implicated. One way or another, we need to be able to reproduce the problem on a clean system before we can confirm a bug.

Traceback (most recent call last):
  File "/opt/netbox/venv/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/venv/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/venv/lib/python3.11/site-packages/django/views/generic/base.py", line 104, in view
    return self.dispatch(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/venv/lib/python3.11/site-packages/django/views/generic/base.py", line 143, in dispatch
    return handler(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/netbox/netbox/views/misc.py", line 83, in get
    results = search_backend.search(
              
  File "/opt/netbox/netbox/netbox/search/backends.py", line 174, in search
    objects = [r for r in results if r.object_type == object_type]
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/venv/lib/python3.11/site-packages/django/db/models/query.py", line 2127, in __iter__
    self._fetch_all()
    ^^^^^^^^^^^^^^^^^
  File "/opt/netbox/venv/lib/python3.11/site-packages/django/db/models/query.py", line 2116, in _fetch_all
    self._prefetch_related_objects()
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/venv/lib/python3.11/site-packages/django/db/models/query.py", line 2095, in _prefetch_related_objects
    prefetch_related_objects(self._result_cache, *self._prefetch_related_lookups)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/venv/lib/python3.11/site-packages/django/db/models/query.py", line 2381, in prefetch_related_objects
    obj_list, additional_lookups = prefetch_one_level(
                                   
  File "/opt/netbox/venv/lib/python3.11/site-packages/django/db/models/query.py", line 2545, in prefetch_one_level
    ) = prefetcher.get_prefetch_querysets(
        
  File "/opt/netbox/venv/lib/python3.11/site-packages/django/contrib/contenttypes/fields.py", line 230, in get_prefetch_querysets
    ret_val.extend(ct.get_all_objects_for_this_type(pk__in=fkeys))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/venv/lib/python3.11/site-packages/django/contrib/contenttypes/models.py", line 190, in get_all_objects_for_this_type
    return self.model_class()._base_manager.using(self._state.db).filter(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Exception Type: AttributeError at /search/
Exception Value: 'NoneType' object has no attribute '_base_manager'

@Azmodeszer
Copy link
Contributor Author

Azmodeszer commented May 13, 2024

Internal Server Error: /search/
Traceback (most recent call last):
  File "/opt/netbox-main/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/opt/netbox-main/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/opt/netbox-main/venv/lib/python3.10/site-packages/django/views/generic/base.py", line 104, in view
    return self.dispatch(request, *args, **kwargs)
  File "/opt/netbox-main/venv/lib/python3.10/site-packages/django/views/generic/base.py", line 143, in dispatch
    return handler(request, *args, **kwargs)
  File "/opt/netbox/netbox/netbox/views/misc.py", line 83, in get
    results = search_backend.search(
  File "/opt/netbox/netbox/netbox/search/backends.py", line 174, in search
    objects = [r for r in results if r.object_type == object_type]
  File "/opt/netbox-main/venv/lib/python3.10/site-packages/django/db/models/query.py", line 2127, in __iter__
    self._fetch_all()
  File "/opt/netbox-main/venv/lib/python3.10/site-packages/django/db/models/query.py", line 2116, in _fetch_all
    self._prefetch_related_objects()
  File "/opt/netbox-main/venv/lib/python3.10/site-packages/django/db/models/query.py", line 2095, in _prefetch_related_objects
    prefetch_related_objects(self._result_cache, *self._prefetch_related_lookups)
  File "/opt/netbox-main/venv/lib/python3.10/site-packages/django/db/models/query.py", line 2381, in prefetch_related_objects
    obj_list, additional_lookups = prefetch_one_level(
  File "/opt/netbox-main/venv/lib/python3.10/site-packages/django/db/models/query.py", line 2545, in prefetch_one_level
    ) = prefetcher.get_prefetch_querysets(
  File "/opt/netbox-main/venv/lib/python3.10/site-packages/django/contrib/contenttypes/fields.py", line 230, in get_prefetch_querysets
    ret_val.extend(ct.get_all_objects_for_this_type(pk__in=fkeys))
  File "/opt/netbox-main/venv/lib/python3.10/site-packages/django/contrib/contenttypes/models.py", line 190, in get_all_objects_for_this_type
    return self.model_class()._base_manager.using(self._state.db).filter(**kwargs)
AttributeError: 'NoneType' object has no attribute '_base_manager'

It's indeed not a fresh install but a system upgraded from the last v3 release. I've seen this bug on two such systems now.

@jeremystretch
Copy link
Member

This issue can occur because NetBox is matching on one or more cached search results that reference a type of object which no longer exists (e.g. because a plugin was removed). If you've removed a plugin (likely due to incompatibility with v4.0), be sure to clear the global search index to remove any stale entries.

@PaulR282
Copy link

This issue can occur because NetBox is matching on one or more cached search results that reference a type of object which no longer exists (e.g. because a plugin was removed). If you've removed a plugin (likely due to incompatibility with v4.0), be sure to clear the global search index to remove any stale entries.

That worked for me. Thanks

@Azmodeszer
Copy link
Contributor Author

No such luck for me. When I try to run the reindex command in the venv, I get:

Traceback (most recent call last):
  File "/opt/netbox-main/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 255, in fetch_command
    app_name = commands[subcommand]
KeyError: 'reindex'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/netbox-main/netbox/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/opt/netbox-main/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/opt/netbox-main/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/netbox-main/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 262, in fetch_command
    settings.INSTALLED_APPS
  File "/opt/netbox-main/venv/lib/python3.10/site-packages/django/conf/__init__.py", line 89, in __getattr__
    self._setup(name)
  File "/opt/netbox-main/venv/lib/python3.10/site-packages/django/conf/__init__.py", line 76, in _setup
    self._wrapped = Settings(settings_module)
  File "/opt/netbox-main/venv/lib/python3.10/site-packages/django/conf/__init__.py", line 190, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/opt/netbox-main/netbox/netbox/settings.py", line 739, in <module>
    plugin = importlib.import_module(plugin_name)
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/opt/netbox-main/venv/lib/python3.10/site-packages/netbox_topology_views/__init__.py", line 1, in <module>
    from extras.plugins import PluginConfig
ImportError: cannot import name 'PluginConfig' from 'extras.plugins' (unknown location)

@PaulR282
Copy link

@Azmodeszer You need to disable the topology views plugin because it is currently not compatible with v4.0

@Azmodeszer
Copy link
Contributor Author

Oh ffs, I'm an idiot... Thanks, done and fixed now.

@jeremystretch jeremystretch removed type: bug A confirmed report of unexpected behavior in the application status: revisions needed This issue requires additional information to be actionable status: needs triage This issue is awaiting triage by a maintainer labels May 13, 2024
@bitcollector1
Copy link

bitcollector1 commented May 16, 2024

I'm seeing this issue when I click on a user in NetBox.....not all users....just one

Screenshot 2024-05-16 at 10 15 30 Screenshot 2024-05-16 at 10 14 10

The re-index did not help with this issue that I stumbled across.

@bitcollector1
Copy link

bitcollector1 commented May 16, 2024

I also tried the following that had helped in the past with a similar issue but no luck this time :(

#13507

(venv) ebay@netdevbox:/opt/netbox/netbox$ python3 manage.py nbshell
### NetBox interactive shell (netdevbox)
### Python 3.12.3 | Django 5.0.6 | NetBox 4.0.2
### lsmodels() will show available models. Use help(<model>) for more info.
>>> 
>>> from netbox.search.backends import search_backend
>>> search_backend.clear()
53173
>>> exit()
(venv) ebay@netdevbox:/opt/netbox/netbox$ python manage.py reindex
Reindexing 81 models.
Clearing cached values... 0 entries deleted.
Indexing models
  netbox_dns.record... 7640 entries cached.
  netbox_dns.view... 2 entries cached.
  netbox_dns.nameserver... 4 entries cached.
  netbox_dns.zone... 10 entries cached.
  netbox_dns.contact... No objects found.
  netbox_dns.registrar... No objects found.
  core.datasource... 9 entries cached.
  core.datafile... 231 entries cached.
  circuits.circuit... No objects found.
  circuits.circuittermination... No objects found.
  circuits.circuittype... 2 entries cached.
  circuits.provider... No objects found.
  circuits.providernetwork... No objects found.
  dcim.cable... 3 entries cached.
  dcim.consoleport... 136 entries cached.
  dcim.consoleserverport... 714 entries cached.
  dcim.device... 5687 entries cached.
  dcim.devicebay... 581 entries cached.
  dcim.devicerole... 39 entries cached.
  dcim.devicetype... 312 entries cached.
  dcim.frontport... 258 entries cached.
  dcim.interface... 18805 entries cached.
  dcim.inventoryitem... 8353 entries cached.
  dcim.location... 29 entries cached.
  dcim.manufacturer... 179 entries cached.
  dcim.module... No objects found.
  dcim.modulebay... No objects found.
  dcim.moduletype... No objects found.
  dcim.platform... 9 entries cached.
  dcim.powerfeed... 55 entries cached.
  dcim.poweroutlet... 1703 entries cached.
  dcim.powerpanel... 4 entries cached.
  dcim.powerport... 1280 entries cached.
  dcim.rack... 38 entries cached.
  dcim.rackreservation... 1 entries cached.
  dcim.rackrole... 29 entries cached.
  dcim.rearport... 252 entries cached.
  dcim.region... 6 entries cached.
  dcim.site... 30 entries cached.
  dcim.sitegroup... 14 entries cached.
  dcim.virtualchassis... No objects found.
  dcim.virtualdevicecontext... No objects found.
  ipam.aggregate... No objects found.
  ipam.asn... 14 entries cached.
  ipam.asnrange... No objects found.
  ipam.fhrpgroup... 2 entries cached.
  ipam.ipaddress... 5560 entries cached.
  ipam.iprange... 107 entries cached.
  ipam.prefix... 450 entries cached.
  ipam.rir... 3 entries cached.
  ipam.role... 2 entries cached.
  ipam.routetarget... No objects found.
  ipam.service... 70 entries cached.
  ipam.servicetemplate... No objects found.
  ipam.vlan... 66 entries cached.
  ipam.vlangroup... No objects found.
  ipam.vrf... 2 entries cached.
  extras.customfield... 76 entries cached.
  extras.journalentry... 228 entries cached.
  extras.webhook... No objects found.
  tenancy.contact... 11 entries cached.
  tenancy.contactgroup... 4 entries cached.
  tenancy.contactrole... 2 entries cached.
  tenancy.tenant... 134 entries cached.
  tenancy.tenantgroup... 27 entries cached.
  virtualization.cluster... No objects found.
  virtualization.clustergroup... No objects found.
  virtualization.clustertype... No objects found.
  virtualization.virtualmachine... No objects found.
  virtualization.vminterface... No objects found.
  virtualization.virtualdisk... No objects found.
  vpn.tunnel... No objects found.
  vpn.ikeproposal... No objects found.
  vpn.ikepolicy... No objects found.
  vpn.ipsecproposal... No objects found.
  vpn.ipsecpolicy... No objects found.
  vpn.ipsecprofile... No objects found.
  vpn.l2vpn... No objects found.
  wireless.wirelesslan... No objects found.
  wireless.wirelesslangroup... No objects found.
  wireless.wirelesslink... No objects found.
Completed. Total entries: 53173

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants