Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#32100 closed Bug (invalid)

Parameter KEY_PREFIX for DummyCache causing test runner to fail

Reported by: Kaustubh Bhalerao Owned by: nobody
Component: Core (Cache system) Version: 3.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Summary:
If the KEY_PREFIX option is present while using the DummyCache backend, the test runner fails with the traceback at the bottom. When running the server, there via runserver there is no issue.

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
    },
    'KEY_PREFIX': "SomeKeyPrefix"
}
Traceback (most recent call last):
  File "/snap/pycharm-professional/215/plugins/python/helpers/pycharm/django_test_manage.py", line 168, in <module>
    utility.execute()
  File "/snap/pycharm-professional/215/plugins/python/helpers/pycharm/django_test_manage.py", line 142, in execute
    _create_command().run_from_argv(self.argv)
  File "/home/.../lib/python3.8/site-packages/django/core/management/commands/test.py", line 23, in run_from_argv
    super().run_from_argv(argv)
  File "/home/.../DJ3/lib/python3.8/site-packages/django/core/management/base.py", line 328, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/.../lib/python3.8/site-packages/django/core/management/base.py", line 369, in execute
    output = self.handle(*args, **options)
  File "/snap/pycharm-professional/215/plugins/python/helpers/pycharm/django_test_manage.py", line 104, in handle
    failures = TestRunner(test_labels, **options)
  File "/snap/pycharm-professional/215/plugins/python/helpers/pycharm/django_test_runner.py", line 254, in run_tests
    return DjangoTeamcityTestRunner(**options).run_tests(test_labels,
  File "/snap/pycharm-professional/215/plugins/python/helpers/pycharm/django_test_runner.py", line 156, in run_tests
    return super(DjangoTeamcityTestRunner, self).run_tests(test_labels, extra_tests, **kwargs)
  File "/home/.../lib/python3.8/site-packages/django/test/runner.py", line 684, in run_tests
    old_config = self.setup_databases(aliases=databases)
  File "/home/.../lib/python3.8/site-packages/django/test/runner.py", line 604, in setup_databases
    return _setup_databases(
  File "/home/.../lib/python3.8/site-packages/django/test/utils.py", line 169, in setup_databases
    connection.creation.create_test_db(
  File "/home/.../lib/python3.8/site-packages/django/db/backends/base/creation.py", line 82, in create_test_db
    call_command('createcachetable', database=self.connection.alias)
  File "/home/.../lib/python3.8/site-packages/django/core/management/__init__.py", line 168, in call_command
    return command.execute(*args, **defaults)
  File "/home/.../lib/python3.8/site-packages/django/core/management/base.py", line 369, in execute
    output = self.handle(*args, **options)
  File "/home/.../lib/python3.8/site-packages/django/core/management/commands/createcachetable.py", line 42, in handle
    cache = caches[cache_alias]
  File "/home/.../lib/python3.8/site-packages/django/core/cache/__init__.py", line 79, in __getitem__
    cache = _create_cache(alias)
  File "/home/.../lib/python3.8/site-packages/django/core/cache/__init__.py", line 47, in _create_cache
    params = {**conf, **kwargs}
TypeError: 'str' object is not a mapping

Error message is pretty clear, but likely requires a more general solution implemented in createcachetable.py when DummyCache backend is being used.

Workaround: Do not add options to DummyCache backend, and potentially update documentation to indicate if options to DummyCache will be a problem.

Change History (2)

comment:1 by Mariusz Felisiak, 4 years ago

Resolution: invalid
Status: newclosed

It's a bug in your settings, KEY_PREFIX should be in 'default':

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
        'KEY_PREFIX': 'SomeKeyPrefix',
    },
}

comment:2 by Kaustubh Bhalerao, 4 years ago

My bad!! tests work with the correct format.

Note: See TracTickets for help on using tickets.
Back to Top