Skip to content

settings/production: Update memcached backend for django >= 3.2

python-memcached backend has been replaced by pymemcache since django 3.2.

Related to #4734 (closed)

Spotted when testing with django 4.1 in docker environment (where python has been bumped to 3.9 as django 4 dropped support for python 3.7).

docker-swh-web-1  | Traceback (most recent call last):
docker-swh-web-1  |   File "/srv/softwareheritage/venv/lib/python3.9/site-packages/django/utils/module_loading.py", line 30, in import_string
docker-swh-web-1  |     return cached_import(module_path, class_name)
docker-swh-web-1  |   File "/srv/softwareheritage/venv/lib/python3.9/site-packages/django/utils/module_loading.py", line 16, in cached_import
docker-swh-web-1  |     return getattr(module, class_name)
docker-swh-web-1  | AttributeError: module 'django.core.cache.backends.memcached' has no attribute 'MemcachedCache'
docker-swh-web-1  | 
docker-swh-web-1  | The above exception was the direct cause of the following exception:
docker-swh-web-1  | 
docker-swh-web-1  | Traceback (most recent call last):
docker-swh-web-1  |   File "/srv/softwareheritage/venv/lib/python3.9/site-packages/django/core/cache/__init__.py", line 47, in create_connection
docker-swh-web-1  |     backend_cls = import_string(backend)
docker-swh-web-1  |   File "/srv/softwareheritage/venv/lib/python3.9/site-packages/django/utils/module_loading.py", line 32, in import_string
docker-swh-web-1  |     raise ImportError(
docker-swh-web-1  | ImportError: Module "django.core.cache.backends.memcached" does not define a "MemcachedCache" attribute/class
docker-swh-web-1  | 
docker-swh-web-1  | The above exception was the direct cause of the following exception:
docker-swh-web-1  | 
docker-swh-web-1  | Traceback (most recent call last):
docker-swh-web-1  |   File "/srv/softwareheritage/venv/bin/django-admin", line 8, in <module>
docker-swh-web-1  |     sys.exit(execute_from_command_line())
docker-swh-web-1  |   File "/srv/softwareheritage/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
docker-swh-web-1  |     utility.execute()
docker-swh-web-1  |   File "/srv/softwareheritage/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 440, in execute
docker-swh-web-1  |     self.fetch_command(subcommand).run_from_argv(self.argv)
docker-swh-web-1  |   File "/srv/softwareheritage/venv/lib/python3.9/site-packages/django/core/management/base.py", line 402, in run_from_argv
docker-swh-web-1  |     self.execute(*args, **cmd_options)
docker-swh-web-1  |   File "/srv/softwareheritage/venv/lib/python3.9/site-packages/django/core/management/base.py", line 448, in execute
docker-swh-web-1  |     output = self.handle(*args, **options)
docker-swh-web-1  |   File "/srv/softwareheritage/venv/lib/python3.9/site-packages/django/core/management/base.py", line 96, in wrapped
docker-swh-web-1  |     res = handle_func(*args, **kwargs)
docker-swh-web-1  |   File "/srv/softwareheritage/venv/lib/python3.9/site-packages/django/core/management/commands/migrate.py", line 97, in handle
docker-swh-web-1  |     self.check(databases=[database])
docker-swh-web-1  |   File "/srv/softwareheritage/venv/lib/python3.9/site-packages/django/core/management/base.py", line 475, in check
docker-swh-web-1  |     all_issues = checks.run_checks(
docker-swh-web-1  |   File "/srv/softwareheritage/venv/lib/python3.9/site-packages/django/core/checks/registry.py", line 88, in run_checks
docker-swh-web-1  |     new_errors = check(app_configs=app_configs, databases=databases)
docker-swh-web-1  |   File "/srv/softwareheritage/venv/lib/python3.9/site-packages/django/core/checks/caches.py", line 65, in check_file_based_cache_is_absolute
docker-swh-web-1  |     cache = caches[alias]
docker-swh-web-1  |   File "/srv/softwareheritage/venv/lib/python3.9/site-packages/django/utils/connection.py", line 62, in __getitem__
docker-swh-web-1  |     conn = self.create_connection(alias)
docker-swh-web-1  |   File "/srv/softwareheritage/venv/lib/python3.9/site-packages/django/core/cache/__init__.py", line 49, in create_connection
docker-swh-web-1  |     raise InvalidCacheBackendError(
docker-swh-web-1  | django.core.cache.backends.base.InvalidCacheBackendError: Could not find backend 'django.core.cache.backends.memcached.MemcachedCache': Module "django.core.cache.backends.memcached" does not define a "MemcachedCache" attribute/class

Merge request reports