Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Update django-stubs (#14510)

Patryk Zawadzki963fbecc7075
diff --git a/poetry.lock b/poetry.lock
index a7b81bc34d..bea7eea887 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -1329,26 +1329,25 @@ sftp = ["paramiko (>=1.15)"]
[[package]]
name = "django-stubs"
-version = "1.16.0"
+version = "4.2.6"
description = "Mypy stubs for Django"
optional = false
-python-versions = ">=3.7"
+python-versions = ">=3.8"
files = [
- {file = "django-stubs-1.16.0.tar.gz", hash = "sha256:1bd96207576cd220221a0e615f0259f13d453d515a80f576c1246e0fb547f561"},
- {file = "django_stubs-1.16.0-py3-none-any.whl", hash = "sha256:c95f948e2bfc565f3147e969ff361ef033841a0b8a51cac974a6cc6d0486732c"},
+ {file = "django-stubs-4.2.6.tar.gz", hash = "sha256:e60b43de662a199db4b15c803c06669e0ac5035614af291cbd3b91591f7dcc94"},
+ {file = "django_stubs-4.2.6-py3-none-any.whl", hash = "sha256:2fcd257884a68dfa02de41ee5410ec805264d9b07d9b5b119e4dea82c7b8345e"},
]
[package.dependencies]
django = "*"
-django-stubs-ext = ">=0.8.0"
-mypy = ">=0.980"
-tomli = "*"
+django-stubs-ext = ">=4.2.5"
+tomli = {version = "*", markers = "python_version < \"3.11\""}
types-pytz = "*"
types-PyYAML = "*"
typing-extensions = "*"
[package.extras]
-compatible-mypy = ["mypy (>=1.1.1,<1.2)"]
+compatible-mypy = ["mypy (>=1.6.0,<1.7.0)"]
[[package]]
name = "django-stubs-ext"
@@ -2776,37 +2775,38 @@ files = [
[[package]]
name = "mypy"
-version = "1.4.1"
+version = "1.6.1"
description = "Optional static typing for Python"
optional = false
-python-versions = ">=3.7"
+python-versions = ">=3.8"
files = [
- {file = "mypy-1.4.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:566e72b0cd6598503e48ea610e0052d1b8168e60a46e0bfd34b3acf2d57f96a8"},
- {file = "mypy-1.4.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:ca637024ca67ab24a7fd6f65d280572c3794665eaf5edcc7e90a866544076878"},
- {file = "mypy-1.4.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0dde1d180cd84f0624c5dcaaa89c89775550a675aff96b5848de78fb11adabcd"},
- {file = "mypy-1.4.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:8c4d8e89aa7de683e2056a581ce63c46a0c41e31bd2b6d34144e2c80f5ea53dc"},
- {file = "mypy-1.4.1-cp310-cp310-win_amd64.whl", hash = "sha256:bfdca17c36ae01a21274a3c387a63aa1aafe72bff976522886869ef131b937f1"},
- {file = "mypy-1.4.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:7549fbf655e5825d787bbc9ecf6028731973f78088fbca3a1f4145c39ef09462"},
- {file = "mypy-1.4.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:98324ec3ecf12296e6422939e54763faedbfcc502ea4a4c38502082711867258"},
- {file = "mypy-1.4.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:141dedfdbfe8a04142881ff30ce6e6653c9685b354876b12e4fe6c78598b45e2"},
- {file = "mypy-1.4.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:8207b7105829eca6f3d774f64a904190bb2231de91b8b186d21ffd98005f14a7"},
- {file = "mypy-1.4.1-cp311-cp311-win_amd64.whl", hash = "sha256:16f0db5b641ba159eff72cff08edc3875f2b62b2fa2bc24f68c1e7a4e8232d01"},
- {file = "mypy-1.4.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:470c969bb3f9a9efcedbadcd19a74ffb34a25f8e6b0e02dae7c0e71f8372f97b"},
- {file = "mypy-1.4.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e5952d2d18b79f7dc25e62e014fe5a23eb1a3d2bc66318df8988a01b1a037c5b"},
- {file = "mypy-1.4.1-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:190b6bab0302cec4e9e6767d3eb66085aef2a1cc98fe04936d8a42ed2ba77bb7"},
- {file = "mypy-1.4.1-cp37-cp37m-win_amd64.whl", hash = "sha256:9d40652cc4fe33871ad3338581dca3297ff5f2213d0df345bcfbde5162abf0c9"},
- {file = "mypy-1.4.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:01fd2e9f85622d981fd9063bfaef1aed6e336eaacca00892cd2d82801ab7c042"},
- {file = "mypy-1.4.1-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:2460a58faeea905aeb1b9b36f5065f2dc9a9c6e4c992a6499a2360c6c74ceca3"},
- {file = "mypy-1.4.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a2746d69a8196698146a3dbe29104f9eb6a2a4d8a27878d92169a6c0b74435b6"},
- {file = "mypy-1.4.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:ae704dcfaa180ff7c4cfbad23e74321a2b774f92ca77fd94ce1049175a21c97f"},
- {file = "mypy-1.4.1-cp38-cp38-win_amd64.whl", hash = "sha256:43d24f6437925ce50139a310a64b2ab048cb2d3694c84c71c3f2a1626d8101dc"},
- {file = "mypy-1.4.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:c482e1246726616088532b5e964e39765b6d1520791348e6c9dc3af25b233828"},
- {file = "mypy-1.4.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:43b592511672017f5b1a483527fd2684347fdffc041c9ef53428c8dc530f79a3"},
- {file = "mypy-1.4.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:34a9239d5b3502c17f07fd7c0b2ae6b7dd7d7f6af35fbb5072c6208e76295816"},
- {file = "mypy-1.4.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:5703097c4936bbb9e9bce41478c8d08edd2865e177dc4c52be759f81ee4dd26c"},
- {file = "mypy-1.4.1-cp39-cp39-win_amd64.whl", hash = "sha256:e02d700ec8d9b1859790c0475df4e4092c7bf3272a4fd2c9f33d87fac4427b8f"},
- {file = "mypy-1.4.1-py3-none-any.whl", hash = "sha256:45d32cec14e7b97af848bddd97d85ea4f0db4d5a149ed9676caa4eb2f7402bb4"},
- {file = "mypy-1.4.1.tar.gz", hash = "sha256:9bbcd9ab8ea1f2e1c8031c21445b511442cc45c89951e49bbf852cbb70755b1b"},
+ {file = "mypy-1.6.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:e5012e5cc2ac628177eaac0e83d622b2dd499e28253d4107a08ecc59ede3fc2c"},
+ {file = "mypy-1.6.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:d8fbb68711905f8912e5af474ca8b78d077447d8f3918997fecbf26943ff3cbb"},
+ {file = "mypy-1.6.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:21a1ad938fee7d2d96ca666c77b7c494c3c5bd88dff792220e1afbebb2925b5e"},
+ {file = "mypy-1.6.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:b96ae2c1279d1065413965c607712006205a9ac541895004a1e0d4f281f2ff9f"},
+ {file = "mypy-1.6.1-cp310-cp310-win_amd64.whl", hash = "sha256:40b1844d2e8b232ed92e50a4bd11c48d2daa351f9deee6c194b83bf03e418b0c"},
+ {file = "mypy-1.6.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:81af8adaa5e3099469e7623436881eff6b3b06db5ef75e6f5b6d4871263547e5"},
+ {file = "mypy-1.6.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:8c223fa57cb154c7eab5156856c231c3f5eace1e0bed9b32a24696b7ba3c3245"},
+ {file = "mypy-1.6.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a8032e00ce71c3ceb93eeba63963b864bf635a18f6c0c12da6c13c450eedb183"},
+ {file = "mypy-1.6.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:4c46b51de523817a0045b150ed11b56f9fff55f12b9edd0f3ed35b15a2809de0"},
+ {file = "mypy-1.6.1-cp311-cp311-win_amd64.whl", hash = "sha256:19f905bcfd9e167159b3d63ecd8cb5e696151c3e59a1742e79bc3bcb540c42c7"},
+ {file = "mypy-1.6.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:82e469518d3e9a321912955cc702d418773a2fd1e91c651280a1bda10622f02f"},
+ {file = "mypy-1.6.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:d4473c22cc296425bbbce7e9429588e76e05bc7342da359d6520b6427bf76660"},
+ {file = "mypy-1.6.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:59a0d7d24dfb26729e0a068639a6ce3500e31d6655df8557156c51c1cb874ce7"},
+ {file = "mypy-1.6.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:cfd13d47b29ed3bbaafaff7d8b21e90d827631afda134836962011acb5904b71"},
+ {file = "mypy-1.6.1-cp312-cp312-win_amd64.whl", hash = "sha256:eb4f18589d196a4cbe5290b435d135dee96567e07c2b2d43b5c4621b6501531a"},
+ {file = "mypy-1.6.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:41697773aa0bf53ff917aa077e2cde7aa50254f28750f9b88884acea38a16169"},
+ {file = "mypy-1.6.1-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:7274b0c57737bd3476d2229c6389b2ec9eefeb090bbaf77777e9d6b1b5a9d143"},
+ {file = "mypy-1.6.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bbaf4662e498c8c2e352da5f5bca5ab29d378895fa2d980630656178bd607c46"},
+ {file = "mypy-1.6.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:bb8ccb4724f7d8601938571bf3f24da0da791fe2db7be3d9e79849cb64e0ae85"},
+ {file = "mypy-1.6.1-cp38-cp38-win_amd64.whl", hash = "sha256:68351911e85145f582b5aa6cd9ad666c8958bcae897a1bfda8f4940472463c45"},
+ {file = "mypy-1.6.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:49ae115da099dcc0922a7a895c1eec82c1518109ea5c162ed50e3b3594c71208"},
+ {file = "mypy-1.6.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:8b27958f8c76bed8edaa63da0739d76e4e9ad4ed325c814f9b3851425582a3cd"},
+ {file = "mypy-1.6.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:925cd6a3b7b55dfba252b7c4561892311c5358c6b5a601847015a1ad4eb7d332"},
+ {file = "mypy-1.6.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:8f57e6b6927a49550da3d122f0cb983d400f843a8a82e65b3b380d3d7259468f"},
+ {file = "mypy-1.6.1-cp39-cp39-win_amd64.whl", hash = "sha256:a43ef1c8ddfdb9575691720b6352761f3f53d85f1b57d7745701041053deff30"},
+ {file = "mypy-1.6.1-py3-none-any.whl", hash = "sha256:4cbe68ef919c28ea561165206a2dcb68591c50f3bcf777932323bc208d949cf1"},
+ {file = "mypy-1.6.1.tar.gz", hash = "sha256:4d01c00d09a0be62a4ca3f933e315455bde83f37f892ba4b08ce92f3cf44bcc1"},
]
[package.dependencies]
@@ -2817,7 +2817,6 @@ typing-extensions = ">=4.1.0"
[package.extras]
dmypy = ["psutil (>=4.0)"]
install-types = ["pip"]
-python2 = ["typed-ast (>=1.4.0,<2)"]
reports = ["lxml"]
[[package]]
@@ -5299,4 +5298,4 @@ test = ["pytest"]
[metadata]
lock-version = "2.0"
python-versions = "~3.9"
-content-hash = "25a5966648cdb366a31e954a543888e415edc45f13d1124c0038f81c136f79bf"
+content-hash = "f653f81dffe86a4a80bc10620ff077f12f07a511bd4aa5ad5e2428627b857068"
diff --git a/pyproject.toml b/pyproject.toml
index 59c4e8536f..f63b8fe287 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -93,9 +93,9 @@ documentation = "https://docs.saleor.io/"
django-debug-toolbar-request-history = "^0"
django-graphiql-debug-toolbar = "^0.2.0"
django-extensions = "^3.1.2"
- django-stubs = "1.16.0"
+ django-stubs = "^4.2.6"
fakeredis = "^2.10"
- mypy = "1.4.1"
+ mypy = "1.6.1"
mypy-extensions = "^1.0.0"
pre-commit = "^3.4"
pytest = "^7.0.1"
diff --git a/requirements_dev.txt b/requirements_dev.txt
index df64749c9e..cd473d6012 100644
--- a/requirements_dev.txt
+++ b/requirements_dev.txt
@@ -63,7 +63,7 @@ django-prices==2.3.0 ; python_version >= "3.9" and python_version < "3.10"
django-redis==5.4.0 ; python_version >= "3.9" and python_version < "3.10"
django-storages[google]==1.14.2 ; python_version >= "3.9" and python_version < "3.10"
django-stubs-ext==4.2.5 ; python_version >= "3.9" and python_version < "3.10"
-django-stubs==1.16.0 ; python_version >= "3.9" and python_version < "3.10"
+django-stubs==4.2.6 ; python_version >= "3.9" and python_version < "3.10"
django-timezone-field==6.0.1 ; python_version >= "3.9" and python_version < "3.10"
django==3.2.22 ; python_version >= "3.9" and python_version < "3.10"
django[bcrypt]==3.2.22 ; python_version >= "3.9" and python_version < "3.10"
@@ -126,7 +126,7 @@ mock==1.0.1 ; python_version >= "3.9" and python_version < "3.10"
mpmath==1.3.0 ; python_version >= "3.9" and python_version < "3.10"
multidict==6.0.4 ; python_version >= "3.9" and python_version < "3.10"
mypy-extensions==1.0.0 ; python_version >= "3.9" and python_version < "3.10"
-mypy==1.4.1 ; python_version >= "3.9" and python_version < "3.10"
+mypy==1.6.1 ; python_version >= "3.9" and python_version < "3.10"
nodeenv==1.8.0 ; python_version >= "3.9" and python_version < "3.10"
oauthlib==3.2.2 ; python_version >= "3.9" and python_version < "3.10"
openpyxl==3.1.2 ; python_version >= "3.9" and python_version < "3.10"
diff --git a/saleor/account/models.py b/saleor/account/models.py
index df7eabf68f..fb13a05c52 100644
--- a/saleor/account/models.py
+++ b/saleor/account/models.py
@@ -239,15 +239,15 @@ class User(
self._effective_permissions = get_permissions()
if not self.is_superuser:
UserPermission = User.user_permissions.through
- user_permission_queryset = UserPermission.objects.filter(
+ user_permission_queryset = UserPermission._default_manager.filter(
user_id=self.pk
).values("permission_id")
UserGroup = User.groups.through
GroupPermission = Group.permissions.through
- user_group_queryset = UserGroup.objects.filter(user_id=self.pk).values(
- "group_id"
- )
+ user_group_queryset = UserGroup._default_manager.filter(
+ user_id=self.pk
+ ).values("group_id")
group_permission_queryset = GroupPermission.objects.filter(
Exists(user_group_queryset.filter(group_id=OuterRef("group_id")))
).values("permission_id")
diff --git a/saleor/account/utils.py b/saleor/account/utils.py
index d4c07b5977..0c9eae6681 100644
--- a/saleor/account/utils.py
+++ b/saleor/account/utils.py
@@ -135,7 +135,7 @@ def retrieve_user_by_email(email):
def get_user_groups_permissions(user: User):
GroupUser = User.groups.through
- group_users = GroupUser.objects.filter(user_id=user.id).values("group_id")
+ group_users = GroupUser._default_manager.filter(user_id=user.id).values("group_id")
GroupPermissions = Group.permissions.through
group_permissions = GroupPermissions.objects.filter(
Exists(group_users.filter(group_id=OuterRef("group_id")))
diff --git a/saleor/app/manifest_validations.py b/saleor/app/manifest_validations.py
index 16b8a46fa7..f76c5e8357 100644
--- a/saleor/app/manifest_validations.py
+++ b/saleor/app/manifest_validations.py
@@ -140,7 +140,7 @@ def clean_manifest_data(manifest_data, raise_for_saleor_version=False):
errors["brand"].append(e)
saleor_permissions = get_permissions().annotate(
- formated_codename=Concat("content_type__app_label", Value("."), "codename")
+ formatted_codename=Concat("content_type__app_label", Value("."), "codename")
)
try:
app_permissions = clean_permissions(
diff --git a/saleor/app/models.py b/saleor/app/models.py
index a034e1bc13..9628f7da76 100644
--- a/saleor/app/models.py
+++ b/saleor/app/models.py
@@ -1,5 +1,5 @@
from collections.abc import Iterable
-from typing import Union
+from typing import Union, cast
from uuid import uuid4
from django.contrib.auth.hashers import make_password
@@ -180,7 +180,8 @@ class AppInstallation(Job):
def set_message(self, message: str, truncate=True):
if truncate:
- max_length = self._meta.get_field("message").max_length
+ message_field = cast(models.Field, self._meta.get_field("message"))
+ max_length = message_field.max_length
if max_length is None:
raise ValueError("Cannot truncate message without max_length")
message = Truncator(message).chars(max_length)
diff --git a/saleor/attribute/models/base.py b/saleor/attribute/models/base.py
index 12b49dd7a8..354c84f492 100644
--- a/saleor/attribute/models/base.py
+++ b/saleor/attribute/models/base.py
@@ -129,21 +129,21 @@ class Attribute(ModelWithMetadata, ModelWithExternalReference):
ProductType,
blank=True,
related_name="product_attributes",
- through="AttributeProduct",
+ through="attribute.AttributeProduct",
through_fields=("attribute", "product_type"),
)
product_variant_types = models.ManyToManyField(
ProductType,
blank=True,
related_name="variant_attributes",
- through="AttributeVariant",
+ through="attribute.AttributeVariant",
through_fields=("attribute", "product_type"),
)
page_types = models.ManyToManyField(
PageType,
blank=True,
related_name="page_attributes",
- through="AttributePage",
+ through="attribute.AttributePage",
through_fields=("attribute", "page_type"),
)
diff --git a/saleor/attribute/models/page.py b/saleor/attribute/models/page.py
index 2d6c7cbf9d..cb58cd5190 100644
--- a/saleor/attribute/models/page.py
+++ b/saleor/attribute/models/page.py
@@ -3,7 +3,7 @@ from django.db import models
from ...core.models import SortableModel
from ...page.models import Page, PageType
-from .base import AssociatedAttributeManager, BaseAssignedAttribute
+from .base import AssociatedAttributeManager, AttributeValue, BaseAssignedAttribute
class AssignedPageAttributeValue(SortableModel):
@@ -43,7 +43,7 @@ class AssignedPageAttribute(BaseAssignedAttribute):
"AttributePage", on_delete=models.CASCADE, related_name="pageassignments"
)
values = models.ManyToManyField(
- "AttributeValue",
+ AttributeValue,
blank=True,
related_name="pageassignments",
through=AssignedPageAttributeValue,
diff --git a/saleor/attribute/models/product.py b/saleor/attribute/models/product.py
index 6b38f805e4..4687219b82 100644
--- a/saleor/attribute/models/product.py
+++ b/saleor/attribute/models/product.py
@@ -3,7 +3,7 @@ from django.db import models
from ...core.models import SortableModel
from ...product.models import Product, ProductType
-from .base import AssociatedAttributeManager, BaseAssignedAttribute
+from .base import AssociatedAttributeManager, AttributeValue, BaseAssignedAttribute
class AssignedProductAttributeValue(SortableModel):
@@ -48,7 +48,7 @@ class AssignedProductAttribute(BaseAssignedAttribute):
"AttributeProduct", on_delete=models.CASCADE, related_name="productassignments"
)
values = models.ManyToManyField(
- "AttributeValue",
+ AttributeValue,
blank=True,
related_name="productassignments",
through=AssignedProductAttributeValue,
diff --git a/saleor/attribute/models/product_variant.py b/saleor/attribute/models/product_variant.py
index 7a4bb09400..cc2f278ead 100644
--- a/saleor/attribute/models/product_variant.py
+++ b/saleor/attribute/models/product_variant.py
@@ -2,7 +2,7 @@ from django.db import models
from ...core.models import SortableModel
from ...product.models import ProductType, ProductVariant
-from .base import AssociatedAttributeManager, BaseAssignedAttribute
+from .base import AssociatedAttributeManager, AttributeValue, BaseAssignedAttribute
class AssignedVariantAttributeValue(SortableModel):
@@ -35,7 +35,7 @@ class AssignedVariantAttribute(BaseAssignedAttribute):
"AttributeVariant", on_delete=models.CASCADE, related_name="variantassignments"
)
values = models.ManyToManyField(
- "AttributeValue",
+ AttributeValue,
blank=True,
related_name="variantassignments",
through=AssignedVariantAttributeValue,
diff --git a/saleor/attribute/utils.py b/saleor/attribute/utils.py
index d8a07eef38..42951aa37a 100644
--- a/saleor/attribute/utils.py
+++ b/saleor/attribute/utils.py
@@ -134,4 +134,4 @@ def sort_assigned_attribute_values(
for index, value_assignment in enumerate(values_assignment):
value_assignment.sort_order = index
- assignment_model.objects.bulk_update(values_assignment, ["sort_order"])
+ assignment_model._default_manager.bulk_update(values_assignment, ["sort_order"])
diff --git a/saleor/checkout/fetch.py b/saleor/checkout/fetch.py
index fbe925b52a..2dd718a402 100644
--- a/saleor/checkout/fetch.py
+++ b/saleor/checkout/fetch.py
@@ -360,7 +360,7 @@ def _get_product_channel_listing(
product_channel_listing = product_channel_listing_mapping.get(product.id)
if product.id not in product_channel_listing_mapping:
for channel_listing in product.channel_listings.all():
- if channel_listing.channel_id == channel_id:
+ if channel_listing.channel_id == channel_id: # type: ignore[attr-defined]
product_channel_listing = channel_listing
product_channel_listing_mapping[product.id] = product_channel_listing
return product_channel_listing
diff --git a/saleor/core/utils/random_data.py b/saleor/core/utils/random_data.py
index 9844a352e9..bdeab53e97 100644
--- a/saleor/core/utils/random_data.py
+++ b/saleor/core/utils/random_data.py
@@ -545,7 +545,7 @@ def create_fake_user(user_password, save=True):
pass
_, max_user_id = connection.ops.integer_field_range(
- User.id.field.get_internal_type() # type: ignore # raw access to field
+ User.id.field.get_internal_type()
)
user = User(
id=fake.random_int(min=1, max=max_user_id),
diff --git a/saleor/discount/utils.py b/saleor/discount/utils.py
index a15acf3d8b..80e8d661e8 100644
--- a/saleor/discount/utils.py
+++ b/saleor/discount/utils.py
@@ -493,7 +493,7 @@ def _get_rule_to_channel_ids_map(rules: QuerySet):
Exists(rules.filter(id=OuterRef("promotionrule_id")))
)
for promotion_rule_channel in promotion_rule_channels:
- rule_id = promotion_rule_channel.promotionrule_id # type: ignore[attr-defined]
- channel_id = promotion_rule_channel.channel_id # type: ignore[attr-defined]
+ rule_id = promotion_rule_channel.promotionrule_id
+ channel_id = promotion_rule_channel.channel_id
rule_to_channel_ids_map[rule_id].append(channel_id)
return rule_to_channel_ids_map
diff --git a/saleor/graphql/account/dataloaders.py b/saleor/graphql/account/dataloaders.py
index b7f75733e5..f001311bd9 100644
--- a/saleor/graphql/account/dataloaders.py
+++ b/saleor/graphql/account/dataloaders.py
@@ -139,9 +139,9 @@ class AccessibleChannelsByUserIdLoader(BaseAccessibleChannels):
def batch_load(self, keys):
UserGroup = User.groups.through
- user_groups = UserGroup.objects.using(self.database_connection_name).filter(
- user_id__in=keys
- )
+ user_groups = UserGroup._default_manager.using(
+ self.database_connection_name
+ ).filter(user_id__in=keys)
groups = Group.objects.using(self.database_connection_name).filter(
id__in=user_groups.values("group_id")
)
@@ -162,9 +162,9 @@ class RestrictedChannelAccessByUserIdLoader(DataLoader):
def batch_load(self, keys):
UserGroup = User.groups.through
- user_groups = UserGroup.objects.using(self.database_connection_name).filter(
- user_id__in=keys
- )
+ user_groups = UserGroup._default_manager.using(
+ self.database_connection_name
+ ).filter(user_id__in=keys)
groups = Group.objects.using(self.database_connection_name).filter(
id__in=user_groups.values("group_id")
)
diff --git a/saleor/graphql/account/utils.py b/saleor/graphql/account/utils.py
index 4259fb20b4..fc391f11f9 100644
--- a/saleor/graphql/account/utils.py
+++ b/saleor/graphql/account/utils.py
@@ -108,8 +108,8 @@ def can_manage_app(requestor: Union["User", "App", None], app: "App") -> bool:
def get_group_permission_codes(group: Group) -> "QuerySet":
"""Return group permissions in the format '<app label>.<permission codename>'."""
return group.permissions.annotate(
- formated_codename=Concat("content_type__app_label", Value("."), "codename")
- ).values_list("formated_codename", flat=True)
+ formatted_codename=Concat("content_type__app_label", Value("."), "codename")
+ ).values_list("formatted_codename", flat=True) # type: ignore[misc]
def get_groups_which_user_can_manage(user: "User") -> list[Group]:
diff --git a/saleor/graphql/app/mutations/app_fetch_manifest.py b/saleor/graphql/app/mutations/app_fetch_manifest.py
index 1008c2ad0f..b19d3905a2 100644
--- a/saleor/graphql/app/mutations/app_fetch_manifest.py
+++ b/saleor/graphql/app/mutations/app_fetch_manifest.py
@@ -90,14 +90,14 @@ class AppFetchManifest(BaseMutation):
manifest_data["permissions"] = [
grapqhl_types.Permission(
- code=PermissionEnum.get(p.formated_codename), name=p.name
+ code=PermissionEnum.get(p.formatted_codename), name=p.name
)
for p in manifest_data["permissions"]
]
for extension in manifest_data.get("extensions", []):
extension["permissions"] = [
grapqhl_types.Permission(
- code=PermissionEnum.get(p.formated_codename),
+ code=PermissionEnum.get(p.formatted_codename),
name=p.name,
)
for p in extension["permissions"]
diff --git a/saleor/graphql/attribute/utils.py b/saleor/graphql/attribute/utils.py
index 445ef6e205..4241a00f28 100644
--- a/saleor/graphql/attribute/utils.py
+++ b/saleor/graphql/attribute/utils.py
@@ -1099,12 +1099,12 @@ def validate_single_selectable_field(
return
if value:
- max_length = attribute.values.model.name.field.max_length # type: ignore
+ max_length = attribute.values.model.name.field.max_length
if not value.strip():
attribute_errors[AttributeInputErrors.ERROR_BLANK_VALUE].append(
attr_identifier
)
- elif len(value) > max_length:
+ elif max_length and len(value) > max_length:
attribute_errors[AttributeInputErrors.ERROR_MAX_LENGTH].append(
attr_identifier
)
@@ -1278,7 +1278,7 @@ def validate_values(
attribute_errors: T_ERROR_DICT,
):
"""To be deprecated together with `AttributeValueInput.values` field."""
- name_field = attribute.values.model.name.field # type: ignore
+ name_field = attribute.values.model.name.field
is_numeric = attribute.input_type == AttributeInputType.NUMERIC
if get_duplicated_values(values):
attribute_errors[AttributeInputErrors.ERROR_DUPLICATED_VALUES].append(
@@ -1296,7 +1296,7 @@ def validate_values(
attribute_errors[
AttributeInputErrors.ERROR_NUMERIC_VALUE_REQUIRED
].append(attr_identifier)
- elif len(value) > name_field.max_length:
+ elif name_field.max_length and len(value) > name_field.max_length:
attribute_errors[AttributeInputErrors.ERROR_MAX_LENGTH].append(
attr_identifier
)
diff --git a/saleor/graphql/core/mutations.py b/saleor/graphql/core/mutations.py
index ec58232255..d8e308cbd8 100644
--- a/saleor/graphql/core/mutations.py
+++ b/saleor/graphql/core/mutations.py
@@ -1172,6 +1172,8 @@ class FileUpload(BaseMutation):
cls, _root, info: ResolveInfo, /, file
):
file_data: UploadedFile = cast(UploadedFile, info.context.FILES[file])
+ if not file_data.file:
+ raise ValidationError("Received an empty file.")
# add unique text fragment to the file name to prevent file overriding
file_name, format = os.path.splitext(file_data.name or "")
diff --git a/saleor/graphql/translations/schema.py b/saleor/graphql/translations/schema.py
index ab8e3d1857..a6062018a5 100644
--- a/saleor/graphql/translations/schema.py
+++ b/saleor/graphql/translations/schema.py
@@ -162,4 +162,4 @@ class TranslationQueries(graphene.ObjectType):
}
if kind == TranslatableKinds.SALE.value: # type: ignore[attr-defined]
return Promotion.objects.filter(old_sale_id=kind_id).first()
- return models[kind].objects.filter(pk=kind_id).first()
+ return models[kind]._default_manager.filter(pk=kind_id).first()
diff --git a/saleor/graphql/utils/__init__.py b/saleor/graphql/utils/__init__.py
index 54d851f410..0a57031da9 100644
--- a/saleor/graphql/utils/__init__.py
+++ b/saleor/graphql/utils/__init__.py
@@ -181,12 +181,12 @@ def format_permissions_for_display(permissions):
permissions: queryset with permissions
"""
permissions_data = permissions.annotate(
- formated_codename=Concat("content_type__app_label", Value("."), "codename")
- ).values("name", "formated_codename")
+ formatted_codename=Concat("content_type__app_label", Value("."), "codename")
+ ).values("name", "formatted_codename")
formatted_permissions = [
Permission(
- code=PermissionEnum.get(data["formated_codename"]), name=data["name"]
+ code=PermissionEnum.get(data["formatted_codename"]), name=data["name"]
)
for data in permissions_data
]
diff --git a/saleor/page/models.py b/saleor/page/models.py
index affbf35bc3..814782d0e3 100644
--- a/saleor/page/models.py
+++ b/saleor/page/models.py
@@ -33,7 +33,7 @@ class Page(ModelWithMetadata, SeoModel, PublishableModel):
content = SanitizedJSONField(blank=True, null=True, sanitizer=clean_editor_js)
created_at = models.DateTimeField(auto_now_add=True, db_index=True)
- objects = PageManager() # type: ignore[assignment]
+ objects = PageManager() # type: ignore[assignment,misc]
class Meta(ModelWithMetadata.Meta):
ordering = ("slug",)
diff --git a/saleor/product/models.py b/saleor/product/models.py
index 8e4945828d..3370db17b7 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -337,7 +337,9 @@ class ProductVariant(SortableModel, ModelWithMetadata, ModelWithExternalReferenc
product = models.ForeignKey(
Product, related_name="variants", on_delete=models.CASCADE
)
- media = models.ManyToManyField("ProductMedia", through="VariantMedia")
+ media = models.ManyToManyField(
+ "product.ProductMedia", through="product.VariantMedia"
+ )
track_inventory = models.BooleanField(default=True)
is_preorder = models.BooleanField(default=False)
preorder_end_date = models.DateTimeField(null=True, blank=True)
@@ -499,7 +501,7 @@ class ProductVariantChannelListing(models.Model):
promotion_rules = models.ManyToManyField(
PromotionRule,
help_text=("Promotion rules that were included in the discounted price."),
- through="VariantChannelListingPromotionRule",
+ through="product.VariantChannelListingPromotionRule",
blank=True,
)