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

Server error when searching with global search and deactivated plugin #15635

Closed
julianstolp opened this issue Apr 5, 2024 · 2 comments
Closed
Assignees
Labels
severity: medium Results in substantial degraded or broken functionality for specfic workflows status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@julianstolp
Copy link

julianstolp commented Apr 5, 2024

Deployment Type

Self-hosted

NetBox Version

v4.0-beta1

Python Version

3.10

Steps to Reproduce

  1. Install plugin in v3.7.5
  2. create an searchable entry with the plugin
  3. upgrade to v4.0-beta1
  4. disable plugin because its not compatible yet
  5. search something that would return a plugin result
  6. Exception Value: 'NoneType' object has no attribute '_base_manager'

we have one disabled plugin netbox-documents

Maybe somehow related to #11335

Expected Behavior

The search results are displayed as usual

Observed Behavior

Environment:


Request Method: GET
Request URL: https://netbox-url/search/?q=gh

Django Version: 5.0.3
Python Version: 3.10.12
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.humanize',
 'django.forms',
 'corsheaders',
 'debug_toolbar',
 'django_filters',
 'django_htmx',
 'django_tables2',
 'django_prometheus',
 'strawberry_django',
 'mptt',
 'rest_framework',
 'social_django',
 'taggit',
 'timezone_field',
 'core',
 'account',
 'circuits',
 'dcim',
 'ipam',
 'extras',
 'tenancy',
 'users',
 'utilities',
 'virtualization',
 'vpn',
 'wireless',
 'django_rq',
 'drf_spectacular',
 'drf_spectacular_sidecar']
Installed Middleware:
['strawberry_django.middlewares.debug_toolbar.DebugToolbarMiddleware',
 'django_prometheus.middleware.PrometheusBeforeMiddleware',
 'corsheaders.middleware.CorsMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware',
 'django_htmx.middleware.HtmxMiddleware',
 'netbox.middleware.RemoteUserMiddleware',
 'netbox.middleware.CoreMiddleware',
 'netbox.middleware.MaintenanceModeMiddleware',
 'django_prometheus.middleware.PrometheusAfterMiddleware']



Traceback (most recent call last):
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/opt/netbox/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/venv/lib/python3.10/site-packages/django/views/generic/base.py", line 104, in view
    return self.dispatch(request, *args, **kwargs)
  File "/opt/netbox/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/venv/lib/python3.10/site-packages/django/db/models/query.py", line 2127, in __iter__
    self._fetch_all()
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/query.py", line 2116, in _fetch_all
    self._prefetch_related_objects()
  File "/opt/netbox/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/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/venv/lib/python3.10/site-packages/django/db/models/query.py", line 2545, in prefetch_one_level
    ) = prefetcher.get_prefetch_querysets(
  File "/opt/netbox/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/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)

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

@julianstolp julianstolp added status: needs triage This issue is awaiting triage by a maintainer type: bug A confirmed report of unexpected behavior in the application labels Apr 5, 2024
@abhi1693 abhi1693 added status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation severity: medium Results in substantial degraded or broken functionality for specfic workflows and removed status: needs triage This issue is awaiting triage by a maintainer labels Apr 5, 2024
@abhi1693 abhi1693 removed their assignment Apr 5, 2024
@arthanson arthanson self-assigned this Apr 10, 2024
@arthanson arthanson removed the status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation label Apr 10, 2024
@jeremystretch jeremystretch added the status: accepted This issue has been accepted for implementation label Apr 15, 2024
@jeremystretch
Copy link
Member

Per my comment here, we should put more consideration into the process of removing a plugin to prevent issues such as this one. Working around the presence of unsupported data is problematic; ideally we should remove the data entirely. There are other elements of NetBox (e.g. the global change log) which are similarly affected.

I'm marking this as blocked by #10696 for now.

@jeremystretch jeremystretch added status: blocked Another issue or external requirement is preventing implementation and removed status: accepted This issue has been accepted for implementation labels Apr 15, 2024
@jeremystretch jeremystretch self-assigned this Apr 17, 2024
@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed status: blocked Another issue or external requirement is preventing implementation labels Apr 17, 2024
@jeremystretch
Copy link
Member

Under #10696, I've added instructions to run manage.py reindex as part of the procedure for removing an installed plugin. This will clear out any stale search entries and prevent the exception captured above.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
severity: medium Results in substantial degraded or broken functionality for specfic workflows status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants