question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fresh Docker development environment throws builtins.KeyError

See original GitHub issue

After many a try with fresh installation (removed all Docker containers, images, and volumes, rm -rf project_name) Django container invariably throws:

builtins.KeyError
KeyError: 'common'

while visiting /,/about,/users,/accounts, Django admin pages work as expected.

Running on Mac OS X 11.11.6 Docker Version 1.12.0-a (build: 11213) Cookiecutter version: 1.4.0 Local Python Version: 3.5.2 Pip Version: 8.1.2 Cookiecutter settings:

{
   "cookiecutter":{
      "use_celery":"y",
      "use_pycharm":"n",
      "use_lets_encrypt":"y",
      "use_docker":"y",
      "domain_name":"REDACTED",
      "use_python3":"y",
      "version":"0.1.0",
      "use_mailhog":"y",
      "author_name":"REDACTED",
      "use_compressor":"n",
      "use_sentry_for_error_reporting":"y",
      "windows":"n",
      "use_opbeat":"n",
      "postgresql_version":"9.5",
      "project_slug":"REDACTED",
      "timezone":"CET",
      "description":"REDACTED",
      "js_task_runner":"Webpack",
      "email":"REDACTED",
      "use_whitenoise":"y",
      "project_name":"REDACTED",
      "use_heroku":"n",
      "open_source_license":"Not open source"
   }
}

Docker Compose Log:

django_1    | KeyError: 'common'
django_1    | 172.18.0.1 - - [31/Aug/2016 07:03:46] "GET /?__debugger__=yes&cmd=pinauth&pin=423-615-454&s=aAGA2m6dMKNSU22Hbgw1 HTTP/1.1" 500 -
django_1    | Traceback (most recent call last):
django_1    |   File "/usr/local/lib/python3.5/site-packages/django/contrib/staticfiles/handlers.py", line 63, in __call__
django_1    |     return self.application(environ, start_response)
django_1    |   File "/usr/local/lib/python3.5/site-packages/django/core/handlers/wsgi.py", line 177, in __call__
django_1    |     response = self.get_response(request)
django_1    |   File "/usr/local/lib/python3.5/site-packages/django/core/handlers/base.py", line 230, in get_response
django_1    |     response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
django_1    |   File "/usr/local/lib/python3.5/site-packages/django/core/handlers/base.py", line 289, in handle_uncaught_exception
django_1    |     return debug.technical_500_response(request, *exc_info)
django_1    |   File "/usr/local/lib/python3.5/site-packages/django_extensions/management/technical_response.py", line 6, in null_technical_500_response
django_1    |     six.reraise(exc_type, exc_value, tb)
django_1    |   File "/usr/local/lib/python3.5/site-packages/six.py", line 686, in reraise
django_1    |     raise value
django_1    |   File "/usr/local/lib/python3.5/site-packages/django/core/handlers/base.py", line 174, in get_response
django_1    |     response = self.process_exception_by_middleware(e, request)
django_1    |   File "/usr/local/lib/python3.5/site-packages/django/core/handlers/base.py", line 172, in get_response
django_1    |     response = response.render()
django_1    |   File "/usr/local/lib/python3.5/site-packages/django/template/response.py", line 160, in render
django_1    |     self.content = self.rendered_content
django_1    |   File "/usr/local/lib/python3.5/site-packages/django/template/response.py", line 137, in rendered_content
django_1    |     content = template.render(context, self._request)
django_1    |   File "/usr/local/lib/python3.5/site-packages/django/template/backends/django.py", line 95, in render
django_1    |     return self.template.render(context)
django_1    |   File "/usr/local/lib/python3.5/site-packages/django/template/base.py", line 206, in render
django_1    |     return self._render(context)
django_1    |   File "/usr/local/lib/python3.5/site-packages/django/test/utils.py", line 92, in instrumented_test_render
django_1    |     return self.nodelist.render(context)
django_1    |   File "/usr/local/lib/python3.5/site-packages/django/template/base.py", line 992, in render
django_1    |     bit = node.render_annotated(context)
django_1    |   File "/usr/local/lib/python3.5/site-packages/django/template/base.py", line 959, in render_annotated
django_1    |     return self.render(context)
django_1    |   File "/usr/local/lib/python3.5/site-packages/django/template/loader_tags.py", line 173, in render
django_1    |     return compiled_parent._render(context)
django_1    |   File "/usr/local/lib/python3.5/site-packages/django/test/utils.py", line 92, in instrumented_test_render
django_1    |     return self.nodelist.render(context)
django_1    |   File "/usr/local/lib/python3.5/site-packages/django/template/base.py", line 992, in render
django_1    |     bit = node.render_annotated(context)
django_1    |   File "/usr/local/lib/python3.5/site-packages/django/template/base.py", line 959, in render_annotated
django_1    |     return self.render(context)
django_1    |   File "/usr/local/lib/python3.5/site-packages/django/template/loader_tags.py", line 69, in render
django_1    |     result = block.nodelist.render(context)
django_1    |   File "/usr/local/lib/python3.5/site-packages/django/template/base.py", line 992, in render
django_1    |     bit = node.render_annotated(context)
django_1    |   File "/usr/local/lib/python3.5/site-packages/django/template/base.py", line 959, in render_annotated
django_1    |     return self.render(context)
django_1    |   File "/usr/local/lib/python3.5/site-packages/django/template/library.py", line 201, in render
django_1    |     output = self.func(*resolved_args, **resolved_kwargs)
django_1    |   File "/usr/local/lib/python3.5/site-packages/webpack_loader/templatetags/webpack_loader.py", line 40, in render_bundle
django_1    |     return render_as_tags(_get_bundle(bundle_name, extension, config), attrs)
django_1    |   File "/usr/local/lib/python3.5/site-packages/webpack_loader/templatetags/webpack_loader.py", line 32, in _get_bundle
django_1    |     bundle = get_loader(config).get_bundle(bundle_name)
django_1    |   File "/usr/local/lib/python3.5/site-packages/webpack_loader/loader.py", line 79, in get_bundle
django_1    |     chunks = assets['chunks'][bundle_name]

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
christippettcommented, Sep 11, 2016

I’ve run into the same problem and this is what I’ve surmised of the issue:

There are only two entry points defined in the Webpack configuration file (main and vendor). In the base.html template there are references to three bundles (main, vendor and common). Since there is no common bundle, you get the KeyError you’re experiencing.

The fix is to remove {% render_bundle 'common' %} from the template file.

0reactions
wiredmindcommented, Sep 3, 2016

@jimbofreedman no, I haven’t. This is not limited to Docker environment. I have set up a fresh project with local development environment and Webpack. Same error, but this time more debug information:

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/

Django Version: 1.9.9
Python Version: 3.5.2
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'crispy_forms',
 'allauth',
 'allauth.account',
 'allauth.socialaccount',
 'mocny_cytat.users.apps.UsersConfig',
 'mocny_cytat.taskapp.celery.CeleryConfig',
 'kombu.transport.django',
 'compressor',
 'webpack_loader',
 'debug_toolbar',
 'django_extensions')
Installed Middleware:
('django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'debug_toolbar.middleware.DebugToolbarMiddleware')


Template error:
In template /Users/marcin/Projects/mocny_cytat/mocny_cytat/templates/pages/home.html, error at line 0
   common   1 : {% extends "base.html" %}

Traceback:

File "/Users/marcin/.virtualenvs/mocny_cytat/lib/python3.5/site-packages/django/core/handlers/base.py" in get_response
  174.                     response = self.process_exception_by_middleware(e, request)

File "/Users/marcin/.virtualenvs/mocny_cytat/lib/python3.5/site-packages/django/core/handlers/base.py" in get_response
  172.                     response = response.render()

File "/Users/marcin/.virtualenvs/mocny_cytat/lib/python3.5/site-packages/django/template/response.py" in render
  160.             self.content = self.rendered_content

File "/Users/marcin/.virtualenvs/mocny_cytat/lib/python3.5/site-packages/django/template/response.py" in rendered_content
  137.         content = template.render(context, self._request)

File "/Users/marcin/.virtualenvs/mocny_cytat/lib/python3.5/site-packages/django/template/backends/django.py" in render
  95.             return self.template.render(context)

File "/Users/marcin/.virtualenvs/mocny_cytat/lib/python3.5/site-packages/django/template/base.py" in render
  206.                     return self._render(context)

File "/Users/marcin/.virtualenvs/mocny_cytat/lib/python3.5/site-packages/django/test/utils.py" in instrumented_test_render
  92.     return self.nodelist.render(context)

File "/Users/marcin/.virtualenvs/mocny_cytat/lib/python3.5/site-packages/django/template/base.py" in render
  992.                 bit = node.render_annotated(context)

File "/Users/marcin/.virtualenvs/mocny_cytat/lib/python3.5/site-packages/django/template/base.py" in render_annotated
  959.             return self.render(context)

File "/Users/marcin/.virtualenvs/mocny_cytat/lib/python3.5/site-packages/django/template/loader_tags.py" in render
  173.         return compiled_parent._render(context)

File "/Users/marcin/.virtualenvs/mocny_cytat/lib/python3.5/site-packages/django/test/utils.py" in instrumented_test_render
  92.     return self.nodelist.render(context)

File "/Users/marcin/.virtualenvs/mocny_cytat/lib/python3.5/site-packages/django/template/base.py" in render
  992.                 bit = node.render_annotated(context)

File "/Users/marcin/.virtualenvs/mocny_cytat/lib/python3.5/site-packages/django/template/base.py" in render_annotated
  959.             return self.render(context)

File "/Users/marcin/.virtualenvs/mocny_cytat/lib/python3.5/site-packages/django/template/loader_tags.py" in render
  69.                 result = block.nodelist.render(context)

File "/Users/marcin/.virtualenvs/mocny_cytat/lib/python3.5/site-packages/django/template/base.py" in render
  992.                 bit = node.render_annotated(context)

File "/Users/marcin/.virtualenvs/mocny_cytat/lib/python3.5/site-packages/django/template/base.py" in render_annotated
  959.             return self.render(context)

File "/Users/marcin/.virtualenvs/mocny_cytat/lib/python3.5/site-packages/django/template/library.py" in render
  201.         output = self.func(*resolved_args, **resolved_kwargs)

File "/Users/marcin/.virtualenvs/mocny_cytat/lib/python3.5/site-packages/webpack_loader/templatetags/webpack_loader.py" in render_bundle
  40.     return render_as_tags(_get_bundle(bundle_name, extension, config), attrs)

File "/Users/marcin/.virtualenvs/mocny_cytat/lib/python3.5/site-packages/webpack_loader/templatetags/webpack_loader.py" in _get_bundle
  32.     bundle = get_loader(config).get_bundle(bundle_name)

File "/Users/marcin/.virtualenvs/mocny_cytat/lib/python3.5/site-packages/webpack_loader/loader.py" in get_bundle
  79.             chunks = assets['chunks'][bundle_name]

Exception Type: KeyError at /
Exception Value: 'common'
Read more comments on GitHub >

github_iconTop Results From Across the Web

Fresh Docker development environment throws builtins.KeyError
After many a try with fresh installation (removed all Docker containers, images, and volumes, rm -rf project_name) Django container ...
Read more >
Python throws KeyError when exporting environment variables
It seems that you're meant to set environment variables for a Docker session using built-in Dockerfile functionality.
Read more >
Get started with development Containers in Visual Studio Code
First your image is built from the supplied Docker file or image name. Then a container is created and started using some of...
Read more >
[Solved]-Python throws KeyError when exporting environment ...
Coding example for the question Python throws KeyError when exporting environment variables-docker.
Read more >
AWS Cloud Development Kit (AWS CDK) v2 - Developer Guide
AWS Cloud Development Kit (AWS CDK) v2: Developer Guide ... Configure with properties and methods, not environment variables . ... Built-in help ....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found