Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DjangoCMS TypeError: from_db_value() missing 1 required positional argument: 'context' after upgrade to 3.7.2 w/ Django 3.0.1

I had a working DjangoCMS application running DjangoCMS 3.7.1 and Django 2.2, however after I just bumped the DjangoCMS version to 3.7.2 and with it, Django to 3.0.1, I am now getting a render error on a page that I have a simple list view.

The site will load my custom account login page just fine, but once logged in, the listview breaks and displays this error: Traceback

django.request ERROR 2020-04-26 21:15:16,809 log 461 140647593613056 Internal Server Error: /en/
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 145, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 143, in _get_response
    response = response.render()
  File "/usr/local/lib/python3.8/site-packages/django/template/response.py", line 105, in render
    self.content = self.rendered_content
  File "/usr/local/lib/python3.8/site-packages/django/template/response.py", line 83, in rendered_content
    return template.render(context, self._request)
  File "/usr/local/lib/python3.8/site-packages/django/template/backends/django.py", line 61, in render
    return self.template.render(context)
  File "/usr/local/lib/python3.8/site-packages/django/template/base.py", line 171, in render
    return self._render(context)
  File "/usr/local/lib/python3.8/site-packages/django/test/utils.py", line 95, in instrumented_test_render
    return self.nodelist.render(context)
  File "/usr/local/lib/python3.8/site-packages/django/template/base.py", line 936, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.8/site-packages/django/template/base.py", line 903, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.8/site-packages/django/template/loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "/usr/local/lib/python3.8/site-packages/django/test/utils.py", line 95, in instrumented_test_render
    return self.nodelist.render(context)
  File "/usr/local/lib/python3.8/site-packages/django/template/base.py", line 936, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.8/site-packages/django/template/base.py", line 903, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.8/site-packages/classytags/core.py", line 154, in render
    return self.render_tag(context, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/sekizai/templatetags/sekizai_tags.py", line 88, in render_tag
    rendered_contents = nodelist.render(context)
  File "/usr/local/lib/python3.8/site-packages/django/template/base.py", line 936, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.8/site-packages/django/template/base.py", line 903, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.8/site-packages/classytags/core.py", line 154, in render
    return self.render_tag(context, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/cms/templatetags/cms_tags.py", line 447, in render_tag
    return toolbar.render_with_structure(context, nodelist)
  File "/usr/local/lib/python3.8/site-packages/cms/toolbar/toolbar.py", line 477, in render_with_structure
    rendered_contents = nodelist.render(context)
  File "/usr/local/lib/python3.8/site-packages/django/template/base.py", line 936, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.8/site-packages/django/template/base.py", line 903, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.8/site-packages/django/template/loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "/usr/local/lib/python3.8/site-packages/django/template/base.py", line 936, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.8/site-packages/django/template/base.py", line 903, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.8/site-packages/django/template/defaulttags.py", line 309, in render
    return nodelist.render(context)
  File "/usr/local/lib/python3.8/site-packages/django/template/base.py", line 936, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.8/site-packages/django/template/base.py", line 903, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.8/site-packages/django/template/loader_tags.py", line 188, in render
    return template.render(context)
  File "/usr/local/lib/python3.8/site-packages/django/template/base.py", line 173, in render
    return self._render(context)
  File "/usr/local/lib/python3.8/site-packages/django/test/utils.py", line 95, in instrumented_test_render
    return self.nodelist.render(context)
  File "/usr/local/lib/python3.8/site-packages/django/template/base.py", line 936, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.8/site-packages/django/template/base.py", line 903, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.8/site-packages/django/template/defaulttags.py", line 166, in render
    len_values = len(values)
  File "/usr/local/lib/python3.8/site-packages/django/db/models/query.py", line 258, in __len__
    self._fetch_all()
  File "/usr/local/lib/python3.8/site-packages/django/db/models/query.py", line 1261, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/usr/local/lib/python3.8/site-packages/django/db/models/query.py", line 74, in __iter__
    for row in compiler.results_iter(results):
  File "/usr/local/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1081, in apply_converters
    value = converter(value, expression, connection)
TypeError: from_db_value() missing 1 required positional argument: 'context'
django.server ERROR 2020-04-26 21:15:19,051 basehttp 461 140647593613056 "GET /en/ HTTP/1.1" 500 314261

pipfreeze

amqp==2.5.2
asgiref==3.2.7
astroid==2.3.3
attrs==19.3.0
beautifulsoup4==4.9.0
billiard==3.6.3.0
boto==2.49.0
celery==4.4.2
certifi==2020.4.5.1
chardet==3.0.4
coverage==5.1
dicttoxml==1.7.4
Django==3.0.1
django-appconf==1.0.4
django-bootstrap-form==3.4
django-classy-tags==1.0.0
django-cms==3.7.2
django-crispy-forms==1.9.0
django-debug-toolbar==2.2
django-environ==0.4.5
django-extensions==2.2.9
django-filer==1.7.0
django-formtools==2.2
django-ipware==2.1.0
django-js-asset==1.2.2
django-mail-queue==3.2.4
django-meta==1.6.1
django-model-utils==4.0.0
django-money==1.1
django-mptt==0.11.0
django-parler==2.0.1
django-polymorphic==2.1.2
django-reversion==3.0.7
django-robots==4.0
django-sekizai==1.1.0
django-select2==7.2.3
django-storages==1.9.1
django-taggit==1.2.0
django-taggit-autosuggest==0.3.8
django-taggit-templatetags==0.2.5
django-templatetag-sugar==1.0
django-treebeard==4.3.1
django-user-accounts==3.0.0
djangocms-admin-style==1.5.0
djangocms-attributes-field==1.2.0
djangocms-bootstrap4==1.6.0
djangocms-file==2.4.0
djangocms-googlemap==1.4.0
djangocms-icon==1.5.0
djangocms-link==2.6.0
djangocms-picture==2.4.0
djangocms-snippet==2.3.0
djangocms-style==2.3.0
djangocms-text-ckeditor==3.9.0
djangocms-video==2.3.0
djangorestframework==3.11.0
easy-thumbnails==2.7
fancycompleter==0.9.1
gunicorn==20.0.4
html5lib==1.0.1
idna==2.9
isort==4.3.21
kombu==4.6.8
lazy-object-proxy==1.4.3
mccabe==0.6.1
mimeparse==0.1.3
more-itertools==8.2.0
packaging==20.3
pdbpp==0.10.2
Pillow==7.1.2
pluggy==0.13.1
psycopg2-binary==2.8.5
py==1.8.1
py-moneyed==0.8.0
Pygments==2.6.1
pylint==2.4.4
pyparsing==2.4.7
pyrepl==0.9.0
pytest==5.4.1
pytest-django==3.9.0
pytest-pythonpath==0.7.3
python-dateutil==2.8.1
pytz==2019.3
pyuploadcare==2.6.0
redis==3.4.1
requests==2.23.0
six==1.14.0
soupsieve==2.0
sqlparse==0.3.1
Unidecode==1.1.1
urllib3==1.25.9
vine==1.3.0
wcwidth==0.1.9
webencodings==0.5.1
whitenoise==5.0.1
wmctrl==0.3
wrapt==1.11.2

View

class ProductView(LoginRequiredMixin, ListView):
    template_name = "products/index.html"
    model = models.Product

    def get_queryset(self):
        qs = super().get_queryset()
        tag = self.request.GET.get("tag")
        if tag:
            qs = qs.filter(tags__slug=tag)

        strain = self.request.GET.get("strain")
        if strain:
            qs = qs.filter(strain__label__icontains=strain)

        return qs

When I step through the code of the view, by dropping a pdb into the setup method, I get to this render call noted below where the traceback starts, it seems:

129             # If the response supports deferred rendering, apply template
 130             # response middleware and then render the response
 131             elif hasattr(response, 'render') and callable(response.render):
 132                 for middleware_method in self._template_response_middleware:
 133                     response = middleware_method(request, response)
 134                     # Complain if the template response middleware returned None (a common error).
 135                     if response is None:
 136                         raise ValueError(
 137                             "%s.process_template_response didn't return an "
 138                             "HttpResponse object. It returned None instead."
 139                             % (middleware_method.__self__.__class__.__name__)
 140                         )
 141
 142                 try:
 143  ->                 response = response.render()
 144                 except Exception as e:
 145                     response = self.process_exception_by_middleware(e, request)
 146
 147             return response
(Pdb++)
TypeError: from_db_value() missing 1 required positional argument: 'context'
[62] > /usr/local/lib/python3.8/site-packages/django/core/handlers/base.py(143)_get_response()
-> response = response.render()
> /usr/local/lib/python3.8/site-packages/django/core/handlers/base.py(143)

Any direction or assistance would be greatly appreciated, also happy to provide more context where necessary -- I'm pretty new to Stackoverflow.

like image 948
Ryan F Avatar asked Jan 01 '23 03:01

Ryan F


1 Answers

I ran into the same issue upgrading DjangoCMS to 3.7.2. I believe the context argument was removed in Django 3 (source). The problem for me was djangocms-text-ckeditor doesn't support Django 3 yet. More specifically, HTMLField in my model didn't work. I opened an issue here if you want to comment on it as others have done. Maybe it will get them to fix it sooner. For now, you will probably have to wait till it's fixed. Cheers!

like image 54
Michael Bird Avatar answered Jan 04 '23 13:01

Michael Bird