You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
fromdjango.dbimportmodelsclassCustomJSONField(models.JSONField):
deffrom_db_value(self,value,expression,connection):
super_value=super().from_db_value(value,expression,connection)
# Convert value from JSON field further...returnsuper_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:
python version: 3.8.5
django version: 3.2.12
mypy version: 0.942
django-stubs version: 1.9.0
The text was updated successfully, but these errors were encountered:
Bug report
What's wrong
When attempting to call the superclass
from_db_value
in a class that inherits fromdjango.db.models.JSONField
, mypy does not believe thatfrom_db_value
is defined but it is.gives the mypy error
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
python
version: 3.8.5django
version: 3.2.12mypy
version: 0.942django-stubs
version: 1.9.0The text was updated successfully, but these errors were encountered: