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.

Upgraded Django 1.8 to 1.11, getting lots of VariableDoesNotExist errors

See original GitHub issue

The keys it’s trying to look for include:

  • in pipeline/js.html:
    • async
    • defer
  • in pipeline/css.html:
    • title
    • charset

The keys available are:

  • url
  • media (only available in pipeline/css.html
  • type

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
asfaltboycommented, Jun 5, 2019

The most prominent place where this always appears in pipeline is pipeline/css.html

All 3 variables media, title and charset don’t have default values and raise a KeyError in the renderer. Adding a default value in pipeline’s render context will resolve this, and most probably reduce some noise (which could result in a slight performance boost).

I can submit a PR if adding defaults sounds reasonable, but not sure what I would go with, probably either empty string or None , what do you say @hsiaoyi0504 ?

05-06-2019 06:13:13 DEBUG   MainProcess 64398 django.template [base.py:878] Exception while resolving variable 'media' in template 'pipeline/css.html'.
Traceback (most recent call last):
  File "/Users/pavel.savchenko/.virtualenvs/test/lib/python3.6/site-packages/django/template/base.py", line 835, in _resolve_lookup
    current = current[bit]
  File "/Users/pavel.savchenko/.virtualenvs/test/lib/python3.6/site-packages/django/template/context.py", line 83, in __getitem__
    raise KeyError(key)
KeyError: 'media'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/pavel.savchenko/.virtualenvs/test/lib/python3.6/site-packages/django/template/base.py", line 841, in _resolve_lookup
    if isinstance(current, BaseContext) and getattr(type(current), bit):
AttributeError: type object 'Context' has no attribute 'media'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/pavel.savchenko/.virtualenvs/test/lib/python3.6/site-packages/django/template/base.py", line 849, in _resolve_lookup
    current = current[int(bit)]
ValueError: invalid literal for int() with base 10: 'media'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/pavel.savchenko/.virtualenvs/test/lib/python3.6/site-packages/django/template/base.py", line 856, in _resolve_lookup
    (bit, current))  # missing attribute
django.template.base.VariableDoesNotExist: Failed lookup for key [media] in [{'True': True, 'False': False, 'None': None}, {'type': 'text/css', 'url': '/static/ui/assets/styles/styles.css'}]
0reactions
delenamalancommented, Nov 25, 2020

Solution for us was to create default “extra content” objects and add it to all of our stylesheets and scripts, e.g.:

default_stylesheet_extra_content = {
    'media': 'all',
    'charset': None,
    'title': None,
}

PIPELINE['STYLESHEETS'] = {
    'countdown': {
        'source_filenames': (
            'css/jquery.countdown-v1.6.0.css',
            'sass/countdown.scss',
        ),
        'output_filename': 'css/countdown.css',
        'extra_context': default_stylesheet_extra_content, 
    },
   ...
}

default_js_extra_content = {
    'async': False,
    'defer': False,
}

PIPELINE['JAVASCRIPT'] = {
    'feeds': {
        'source_filenames': (
            'js/feeds.js',
        ),
        'output_filename': 'js/feeds.js',
        'extra_context': default_js_extra_content, 
    },
   ...
}

@asfaltboy’s suggested solution would’ve been great though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error loading admin page after upgrading to django-1.11
So previously, I was using django-1.8 version & I am in the process of upgrading to django-1.11. When I load my /admin page,...
Read more >
Upgrading templates to Django 1.8
A new setting was introduced in Django 1.8: TEMPLATES . All existing template-related settings were deprecated. During the deprecation period, Django will ...
Read more >
Migrating Django 1.6 to 1.11. Field Notes | by Jim Simon
This deployment strategy was not planned, but came as a solution to having to large of a delta between Django 1.6 in Django...
Read more >
Release Notes - Django REST framework
Release Notes. Versioning. Minor version numbers (0.0.x) are used for changes that are API compatible. You should be able to upgrade between minor...
Read more >
@media, MathML, and Django 1.11: MDN Changelog for May ...
They updated submodules for the 1.7 effort, and switched to hashed requirements files for 1.8. A lot of codebase and process improvements were ......
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