Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

from_db_value not defined in models.JSONField interface #934

Closed
RobertKingOctopus opened this issue Apr 26, 2022 · 0 comments · Fixed by #1879
Closed

from_db_value not defined in models.JSONField interface #934

RobertKingOctopus opened this issue Apr 26, 2022 · 0 comments · Fixed by #1879
Labels
bug Something isn't working

Comments

@RobertKingOctopus
Copy link

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:
  • python version: 3.8.5
  • django version: 3.2.12
  • mypy version: 0.942
  • django-stubs version: 1.9.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

1 participant