I’ve just plugged this old JSONField model snippet into my django application. It looks like it’s working, but throws this warning whenever the server revalidates:
$ sudo python manage.py runserver
Validating models...
/opt/bitnami/apps/django/lib/python2.6/site-packages/django/db/models/fields/subclassing.py:80:
DeprecationWarning: A Field class whose get_db_prep_save method hasn't been updated to take a `connection` argument.
new_class = super(SubfieldBase, cls).__new__(cls, name, bases, attrs)
0 errors found
What does this mean? How do I fix it?
It’s a warning telling you that the the custom JSON field implemented in that snippet hasn’t included the connection argument that has been introduced in django 1.2 due to multiple database support being implemented.
With regards the method itself: If you are writing a custom model field, you can use the get_db_prep_save to convert the python object you are working with (in this case a JSON object) into a form that the database backend can manage (in this case a string) before it is saved to the DB. Here are the release notes mentioning it
With regard the connection argument, it refers to the current database (at the time of execution – to get the default you can call
django.db.connection) and it is included to ensure that the correct database is provided when calling that method so that any custom backend logic or convertions can be carried out before the value is saved to the db. You can read more about connections and cursors here