[Django]-From_db_value() takes 4 positional arguments but 5 were given Django

4👍

TL;DR:

Most likely, jsonfield package is not incompatible with Django==1.11.18


Details:

You are using Django in version 1.11.18, which requires 5 positional arguments for from_db_value method and do not support JSONFields.

You are also using django-notifications package, which internally uses jsonfield>=1.0.3 package. Since there is no max. version set, django-notifications uses the newest version of jsonfield package.

The newest versions of jsonfield (3.0.0 and higher) doesn’t support Django below 2.2. One of the reasons is that it takes only 4 arguments instead of 5.

The highest version of jsonfield that supports Django 1.11 is jsonfield==2.1.1

Please check the version of installed jsonfield package (use grep only if you’re on unix sytem):

pip freeze | grep jsonfield

If it’s 3.0.0 or more, you may try to downgrade it to 2.1.1. Be aware that it may (or may not) cause other compatibility issues with other packages.

1👍

I got the same error:

  File "/home/django/lee3/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 833, in apply_converters
    value = converter(value, expression, self.connection, self.query.context)
TypeError: from_db_value() takes 4 positional arguments but 5 were given

The 'from_db_value' it was complaining about was in /picklefield/fields.py.

Changed line 184:
def from_db_value(self, value, expression, connection):
to:
def from_db_value(self, value, expression, connection, context=None):
Everything works fine now.

Leave a comment