django-stubs
django-stubs copied to clipboard
from_db_value not defined in models.JSONField interface
Bug report
What's wrong
When attempting to call the superclass from_db_value in a class that inherits from django.db.models.JSONField, mypy does not believe that from_db_value is defined but it is.
from django.db import models
class CustomJSONField(models.JSONField):
def from_db_value(self,value,expression,connection):
super_value = super().from_db_value(value,expression,connection)
# Convert value from JSON field further...
return super_value
gives the mypy error
error: "from_db_value" undefined in superclass
How is that should be
Django's JSONField implementation explicitly defines a from_db_value, to handle the serialisation of a python dictionary to a json string. As such it probably should also be defined in the JSONField interface provided by django-stubs? (it is not defined in the default Field interface as it is not a mandatory method to have defined).
Please let me know if there is a better way to inherit from this class that avoids this error?
System information
- OS:
pythonversion: 3.8.5djangoversion: 3.2.12mypyversion: 0.942django-stubsversion: 1.9.0