typeddjango / django-stubs

PEP-484 stubs for Django
MIT License
1.59k stars 441 forks source link

Django stubs doesn`t support updating JSON field through Django ORM #727

Open mcxemic opened 3 years ago

mcxemic commented 3 years ago

Bug report

Django stubs doesn`t support operations on JSON fields using F operator

What's wrong

Since the 9.5 version, Postgres supports '-' operator for JSON fields. It removes key: value from the object. Here the example that works fine:

from django.db import models
from django.contrib.postgres.fields import JSONField

class A(models.Model):
    some_data = JSONField()

A.objects.create(some_data={'key': 'value'})

query = A.objects.filter(id=1).update(
    some_data=(F('some_data') - 'key'),
)

But mypy returns

file.py:1: note: In function "function_name":
file.py:1: error: Unsupported operand types for - ("F" and "str") [operator] some_data=(F('some_data') - 'key'),

How is that should be

Operator F should support - operation with str

System information

sobolevn commented 3 years ago

PRs are welcome!