Skip to content

Commit a41c425

Browse files
asottile-sentryasottileq0wpre-commit-ci[bot]
authored
cherry-pick django 5.1 fixes (#25)
* add cache_name for django 5.1 (typeddjango#2365) * 5.1: Deprecate CheckConstraint.check (typeddjango#2331) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --------- Co-authored-by: Anthony Sottile <[email protected]> Co-authored-by: q0w <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent b5bf9aa commit a41c425

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

django-stubs/contrib/contenttypes/fields.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class GenericForeignKey(FieldCacheMixin):
4242
def get_filter_kwargs_for_object(self, obj: Model) -> dict[str, ContentType | None]: ...
4343
def get_forward_related_filter(self, obj: Model) -> dict[str, int]: ...
4444
def check(self, **kwargs: Any) -> list[CheckMessage]: ...
45-
def get_cache_name(self) -> str: ...
4645
def get_content_type(
4746
self, obj: Model | None = ..., id: int | None = ..., using: str | None = ..., model: type[Model] | None = ...
4847
) -> ContentType: ...

django-stubs/db/models/constraints.pyi

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,26 @@ class BaseConstraint:
4040

4141
class CheckConstraint(BaseConstraint):
4242
check: Q | BaseExpression
43+
condition: Q | BaseExpression
44+
45+
@overload
46+
@deprecated("The check keyword argument is deprecated in favor of condition and will be removed in Django 6.0")
4347
def __init__(
4448
self,
4549
*,
50+
name: str,
4651
check: Q | BaseExpression,
52+
violation_error_code: str | None = None,
53+
violation_error_message: _StrOrPromise | None = None,
54+
) -> None: ...
55+
@overload
56+
def __init__(
57+
self,
58+
*,
4759
name: str,
48-
violation_error_code: str | None = ...,
49-
violation_error_message: _StrOrPromise | None = ...,
60+
condition: Q | BaseExpression,
61+
violation_error_code: str | None = None,
62+
violation_error_message: _StrOrPromise | None = None,
5063
) -> None: ...
5164

5265
class UniqueConstraint(BaseConstraint):

django-stubs/db/models/fields/mixins.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
from typing import Any
22

33
from django.db.models.base import Model
4+
from django.utils.functional import cached_property
45

56
NOT_PROVIDED: Any
67

78
class FieldCacheMixin:
89
def get_cache_name(self) -> str: ...
10+
@cached_property
11+
def cache_name(self) -> str: ...
912
def get_cached_value(self, instance: Model, default: Any = ...) -> Model | None: ...
1013
def is_cached(self, instance: Model) -> bool: ...
1114
def set_cached_value(self, instance: Model, value: Model | None) -> None: ...

tests/assert_type/db/models/test_constraints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
name="unique_mess",
1414
)
1515

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

0 commit comments

Comments
 (0)