django-stubs
django-stubs copied to clipboard
check in CheckConstraint should support expression
Bug report
What's wrong
As of Django 3.1 (#30484), the CheckConstraint supports Q
and boolean Expression
, but only Q
is allowed in current type stubs.
By following it is the code snippets from tests/constraints/models.py
that will throw typing error:
models.CheckConstraint(
check=models.expressions.RawSQL(
"price < %s", (1000,), output_field=models.BooleanField()
),
name="%(app_label)s_price_lt_1000_raw",
),
models.CheckConstraint(
check=models.expressions.ExpressionWrapper(
models.Q(price__gt=500) | models.Q(price__lt=500),
output_field=models.BooleanField(),
),
name="%(app_label)s_price_neq_500_wrap",
),
How is that should be
Maybe like #806, make check
accepts Union[Q, Combinable]
.
System information
- OS: Debian 11
-
python
version: 3.9 -
django
version: 3.2 -
mypy
version: 0.931 -
django-stubs
version: 1.9.0 -
django-stubs-ext
version: 0.3.1