Skip to content

Commit

Permalink
5.1: Deprecate CheckConstraint.check (typeddjango#2331)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and asottile-sentry committed Sep 11, 2024
1 parent 115b0c5 commit 69747f7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions django-stubs/db/models/constraints.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,26 @@ class BaseConstraint:

class CheckConstraint(BaseConstraint):
check: Q | BaseExpression
condition: Q | BaseExpression

@overload
@deprecated("The check keyword argument is deprecated in favor of condition and will be removed in Django 6.0")
def __init__(
self,
*,
name: str,
check: Q | BaseExpression,
violation_error_code: str | None = None,
violation_error_message: _StrOrPromise | None = None,
) -> None: ...
@overload
def __init__(
self,
*,
name: str,
violation_error_code: str | None = ...,
violation_error_message: _StrOrPromise | None = ...,
condition: Q | BaseExpression,
violation_error_code: str | None = None,
violation_error_message: _StrOrPromise | None = None,
) -> None: ...

class UniqueConstraint(BaseConstraint):
Expand Down
2 changes: 1 addition & 1 deletion tests/assert_type/db/models/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
name="unique_mess",
)

CheckConstraint(name="less_than_constraint", check=LessThan[Any](F("months"), 1))
CheckConstraint(name="less_than_constraint", check=LessThan[Any](F("months"), 1)) # pyright: ignore[reportDeprecated]

0 comments on commit 69747f7

Please sign in to comment.