Bug 280254 - net-mgmt/netbox: ImportError: cannot import name '_HTML_TYPES' from 'debug_toolbar.middleware'
Summary: net-mgmt/netbox: ImportError: cannot import name '_HTML_TYPES' from 'debug_to...
Status: In Progress
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Kai Knoblich
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-07-13 08:22 UTC by Fredrik Eriksson
Modified: 2024-07-13 17:22 UTC (History)
0 users

See Also:
kai: maintainer-feedback+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fredrik Eriksson 2024-07-13 08:22:09 UTC
After upgrading netbox today I got this message when running the migration post-installation step:

WARNINGS:
?: (debug_toolbar.W001) debug_toolbar.middleware.DebugToolbarMiddleware is missing from MIDDLEWARE.
        HINT: Add debug_toolbar.middleware.DebugToolbarMiddleware to MIDDLEWARE.

I followed the instructions and updated MIDDLEWARE netbox/settings.py which made the warning disappear. When trying to restart netbox afterwards it crashed and I found the following message in the logs:

gunicorn.netbox.error: [7635] Exception in worker process
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/gunicorn/arbiter.py", line 609, in spawn_worker
    worker.init_process()
  File "/usr/local/lib/python3.10/site-packages/gunicorn/workers/gthread.py", line 95, in init_process
    super().init_process()
  File "/usr/local/lib/python3.10/site-packages/gunicorn/workers/base.py", line 134, in init_process
    self.load_wsgi()
  File "/usr/local/lib/python3.10/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python3.10/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/local/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
    return self.load_wsgiapp()
  File "/usr/local/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/local/lib/python3.10/site-packages/gunicorn/util.py", line 371, in import_app
    mod = importlib.import_module(module)
  File "/usr/local/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 "/usr/local/share/netbox/netbox/wsgi.py", line 7, in <module>
    application = get_wsgi_application()
  File "/usr/local/lib/python3.10/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
    return WSGIHandler() 
  File "/usr/local/lib/python3.10/site-packages/django/core/handlers/wsgi.py", line 118, in __init__
    self.load_middleware()
  File "/usr/local/lib/python3.10/site-packages/django/core/handlers/base.py", line 40, in load_middleware
    middleware = import_string(middleware_path)
  File "/usr/local/lib/python3.10/site-packages/django/utils/module_loading.py", line 30, in import_string
    return cached_import(module_path, class_name)
  File "/usr/local/lib/python3.10/site-packages/django/utils/module_loading.py", line 15, in cached_import
    module = import_module(module_path)
  File "/usr/local/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 "/usr/local/lib/python3.10/site-packages/graphiql_debug_toolbar/middleware.py", line 7, in <module>
    from debug_toolbar.middleware import _HTML_TYPES#012ImportError: cannot import name '_HTML_TYPES' from 'debug_toolbar.middleware' (/usr/local/lib/python3.10/site-packages/debug_toolbar/middleware.

Reading some code I found that the _HTML_TYPES is set in debug_toolbar.utils and not debug_toolbar.middleware. After monkey-patching /usr/local/lib/python3.10/site-packages/graphiql_debug_toolbar/middleware.py to import from debug_toolbar.utils instead netbox starts again. I'm guessing this is a dependency-version-incompatibility-thing?

relevant installed packages:
netbox-3.7.8_3
py310-django-debug-toolbar-4.4.6
py310-django-graphiql-debug-toolbar-0.2.0_3
Comment 1 commit-hook freebsd_committer freebsd_triage 2024-07-13 17:12:45 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=255008d84916dfcec497341eb0c2357bbcee5a91

commit 255008d84916dfcec497341eb0c2357bbcee5a91
Author:     Kai Knoblich <kai@FreeBSD.org>
AuthorDate: 2024-07-13 17:07:56 +0000
Commit:     Kai Knoblich <kai@FreeBSD.org>
CommitDate: 2024-07-13 17:11:36 +0000

    www/py-django-graphiql-debug-toolbar: Fix runtime after f8392fba5cb4

    * Add a workaround for py-django-debug-toolbar 4.4.6 or newer to prevent
      following error [1]:

      [...]
        File "/usr/local/lib/python3.11/site-packages/graphiql_debug_toolbar/middleware.py", line 7, in <module>
            from debug_toolbar.middleware import _HTML_TYPES
        ImportError: cannot import name '_HTML_TYPES' from 'debug_toolbar.middleware' (/usr/local/lib/python3.11/site-packages/debug_toolbar/middleware.py)
      [...]

    * Switch to the PEP517 build framework while I'm here.

    * Bump PORTREVISION due package change.

    PR:             280254 [1]
    Reported by:    Fredrik Eriksson [1]

 www/py-django-graphiql-debug-toolbar/Makefile      |  8 ++++--
 ...ch-graphiql__debug__toolbar_middleware.py (new) | 29 ++++++++++++++++++++++
 2 files changed, 35 insertions(+), 2 deletions(-)
Comment 2 Kai Knoblich freebsd_committer freebsd_triage 2024-07-13 17:22:18 UTC
(In reply to Fredrik Eriksson from comment #0)

Hi Fredrik, thank you for the detailed report and your findings!

It looks like www/py-graphiql-debug-toolbar has stopped working with the 4.4.6 upgrade of www/py-django-debug-toolbar in ports f8392fba5cb4.  I committed a workaround which should solve the problem.

I'll try to report this issue to upstream in the next few days and leave this bug open for reference during this time.