ImportError: cannot import name 'Mapping' from 'collections' #3083

Closed
opened 2025-12-29 18:25:28 +01:00 by adam · 3 comments
Owner

Originally created by @cimnine on GitHub (Dec 23, 2019).

Environment

  • Python version: 3.9a
  • NetBox version: 2.7-beta1

Steps to Reproduce

  1. ./manage.py migrate

Expected Behavior

Netbox/Django applies the migrations.

Observed Behavior

An error occurs:

Traceback (most recent call last):
  File "/opt/netbox/netbox/./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 357, in execute
    django.setup()
  File "/usr/local/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python3.9/site-packages/django/apps/registry.py", line 114, in populate
    app_config.import_models()
  File "/usr/local/lib/python3.9/site-packages/django/apps/config.py", line 211, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1016, in _gcd_import
  File "<frozen importlib._bootstrap>", line 993, in _find_and_load
  File "<frozen importlib._bootstrap>", line 977, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 786, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/opt/netbox/netbox/circuits/models.py", line 8, in <module>
    from dcim.models import CableTermination
  File "/opt/netbox/netbox/dcim/models.py", line 18, in <module>
    from extras.models import ConfigContextModel, CustomFieldModel, ObjectChange, TaggedItem
  File "/opt/netbox/netbox/extras/models.py", line 15, in <module>
    from jinja2 import Environment
  File "/usr/local/lib/python3.9/site-packages/jinja2/__init__.py", line 33, in <module>
    from jinja2.environment import Environment, Template
  File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 16, in <module>
    from jinja2.defaults import BLOCK_START_STRING, \
  File "/usr/local/lib/python3.9/site-packages/jinja2/defaults.py", line 32, in <module>
    from jinja2.tests import TESTS as DEFAULT_TESTS
  File "/usr/local/lib/python3.9/site-packages/jinja2/tests.py", line 13, in <module>
    from collections import Mapping
ImportError: cannot import name 'Mapping' from 'collections' (/usr/local/lib/python3.9/collections/__init__.py)

Hints

This appears to be an issue in Jinja2 and appears to be fixed in 2.10.2 of jinja2. (The current release of jinja2 is 2.10.3.)

Originally created by @cimnine on GitHub (Dec 23, 2019). <!-- NOTE: This form is only for reproducible bugs. If you need assistance with NetBox installation, or if you have a general question, DO NOT open an issue. Instead, post to our mailing list: https://groups.google.com/forum/#!forum/netbox-discuss Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report. --> ### Environment * Python version: 3.9a * NetBox version: 2.7-beta1 <!-- Describe in detail the exact steps that someone else can take to reproduce this bug using the current stable release of NetBox (or the current beta release where applicable). Begin with the creation of any necessary database objects and call out every operation being performed explicitly. If reporting a bug in the REST API, be sure to reconstruct the raw HTTP request(s) being made: Don't rely on a wrapper like pynetbox. --> ### Steps to Reproduce 1. `./manage.py migrate` <!-- What did you expect to happen? --> ### Expected Behavior Netbox/Django applies the migrations. <!-- What happened instead? --> ### Observed Behavior An error occurs: ``` Traceback (most recent call last): File "/opt/netbox/netbox/./manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line utility.execute() File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 357, in execute django.setup() File "/usr/local/lib/python3.9/site-packages/django/__init__.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "/usr/local/lib/python3.9/site-packages/django/apps/registry.py", line 114, in populate app_config.import_models() File "/usr/local/lib/python3.9/site-packages/django/apps/config.py", line 211, in import_models self.models_module = import_module(models_module_name) File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1016, in _gcd_import File "<frozen importlib._bootstrap>", line 993, in _find_and_load File "<frozen importlib._bootstrap>", line 977, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 671, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 786, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/opt/netbox/netbox/circuits/models.py", line 8, in <module> from dcim.models import CableTermination File "/opt/netbox/netbox/dcim/models.py", line 18, in <module> from extras.models import ConfigContextModel, CustomFieldModel, ObjectChange, TaggedItem File "/opt/netbox/netbox/extras/models.py", line 15, in <module> from jinja2 import Environment File "/usr/local/lib/python3.9/site-packages/jinja2/__init__.py", line 33, in <module> from jinja2.environment import Environment, Template File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 16, in <module> from jinja2.defaults import BLOCK_START_STRING, \ File "/usr/local/lib/python3.9/site-packages/jinja2/defaults.py", line 32, in <module> from jinja2.tests import TESTS as DEFAULT_TESTS File "/usr/local/lib/python3.9/site-packages/jinja2/tests.py", line 13, in <module> from collections import Mapping ImportError: cannot import name 'Mapping' from 'collections' (/usr/local/lib/python3.9/collections/__init__.py) ``` ### Hints This appears to be an issue in Jinja2 and [appears to be fixed in `2.10.2`](http://jinja.palletsprojects.com/en/2.10.x/changelog/#version-2-10-2) of jinja2. (The current release of jinja2 is `2.10.3`.)
adam closed this issue 2025-12-29 18:25:28 +01:00
Author
Owner

@DanSheps commented on GitHub (Dec 23, 2019):

Thank you for submitting this issue. Before any further work can be done, please upgrade to a stable release of python. Please then update your issue to indicate whether further action is needed.

We do not support alpha releases of python. 3.9-rc (the docker file) uses 3.9.0a2

@DanSheps commented on GitHub (Dec 23, 2019): Thank you for submitting this issue. Before any further work can be done, please upgrade to a stable release of python. Please then update your issue to indicate whether further action is needed. We do not support alpha releases of python. 3.9-rc (the docker file) uses 3.9.0a2
Author
Owner

@cimnine commented on GitHub (Dec 23, 2019):

Yes. All works with Python < 3.9, but this will stop working in Python 3.9. The method in question is already deprecated in 3.7 and 3.8.

So there's no hurry fixing this, but eventually this work needs to be done anyway. So why procrastinate?

@cimnine commented on GitHub (Dec 23, 2019): Yes. All works with Python < 3.9, but this will stop working in Python 3.9. The method in question is already deprecated in 3.7 and 3.8. So there's no hurry fixing this, but eventually this work needs to be done anyway. So why procrastinate?
Author
Owner

@jeremystretch commented on GitHub (Jan 2, 2020):

Static requirements are bumped on every 2.x release; versions are pinned unless there is a specific need to upgrade (e.g. fixing a bug). This will be addressed in the upcoming v2.7 release.

@jeremystretch commented on GitHub (Jan 2, 2020): Static requirements are bumped on every 2.x release; versions are pinned unless there is a specific need to upgrade (e.g. fixing a bug). This will be addressed in the upcoming v2.7 release.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3083