Skip to content

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

Bump Django to 5.2, upgrade mypy, fix problems, and make metadata non-nullable (#17626)

Patryk Zawadzki0f5203fbd31b
diff --git a/poetry.lock b/poetry.lock
index afb4f5a8d8..3feaceb787 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -1036,18 +1036,18 @@ files = [
[[package]]
name = "django"
-version = "4.2.20"
+version = "5.2.1"
description = "A high-level Python web framework that encourages rapid development and clean, pragmatic design."
optional = false
-python-versions = ">=3.8"
+python-versions = ">=3.10"
groups = ["main", "dev"]
files = [
- {file = "Django-4.2.20-py3-none-any.whl", hash = "sha256:213381b6e4405f5c8703fffc29cd719efdf189dec60c67c04f76272b3dc845b9"},
- {file = "Django-4.2.20.tar.gz", hash = "sha256:92bac5b4432a64532abb73b2ac27203f485e40225d2640a7fbef2b62b876e789"},
+ {file = "django-5.2.1-py3-none-any.whl", hash = "sha256:a9b680e84f9a0e71da83e399f1e922e1ab37b2173ced046b541c72e1589a5961"},
+ {file = "django-5.2.1.tar.gz", hash = "sha256:57fe1f1b59462caed092c80b3dd324fd92161b620d59a9ba9181c34746c97284"},
]
[package.dependencies]
-asgiref = ">=3.6.0,<4"
+asgiref = ">=3.8.1"
bcrypt = {version = "*", optional = true, markers = "extra == \"bcrypt\""}
sqlparse = ">=0.3.1"
tzdata = {version = "*", markers = "sys_platform == \"win32\""}
@@ -1254,26 +1254,28 @@ sftp = ["paramiko (>=1.15)"]
[[package]]
name = "django-stubs"
-version = "4.2.7"
+version = "5.1.3"
description = "Mypy stubs for Django"
optional = false
python-versions = ">=3.8"
groups = ["dev"]
files = [
- {file = "django-stubs-4.2.7.tar.gz", hash = "sha256:8ccd2ff4ee5adf22b9e3b7b1a516d2e1c2191e9d94e672c35cc2bc3dd61e0f6b"},
- {file = "django_stubs-4.2.7-py3-none-any.whl", hash = "sha256:4cf4de258fa71adc6f2799e983091b9d46cfc67c6eebc68fe111218c9a62b3b8"},
+ {file = "django_stubs-5.1.3-py3-none-any.whl", hash = "sha256:716758ced158b439213062e52de6df3cff7c586f9f9ad7ab59210efbea5dfe78"},
+ {file = "django_stubs-5.1.3.tar.gz", hash = "sha256:8c230bc5bebee6da282ba8a27ad1503c84a0c4cd2f46e63d149e76d2a63e639a"},
]
[package.dependencies]
+asgiref = "*"
django = "*"
-django-stubs-ext = ">=4.2.7"
-mypy = {version = ">=1.7.0,<1.8.0", optional = true, markers = "extra == \"compatible-mypy\""}
-types-pytz = "*"
+django-stubs-ext = ">=5.1.3"
+mypy = {version = ">=1.12,<1.16", optional = true, markers = "extra == \"compatible-mypy\""}
types-PyYAML = "*"
-typing-extensions = "*"
+typing-extensions = ">=4.11.0"
[package.extras]
-compatible-mypy = ["mypy (>=1.7.0,<1.8.0)"]
+compatible-mypy = ["mypy (>=1.12,<1.16)"]
+oracle = ["oracledb"]
+redis = ["redis"]
[[package]]
name = "django-stubs-ext"
@@ -2678,47 +2680,53 @@ files = [
[[package]]
name = "mypy"
-version = "1.7.1"
+version = "1.15.0"
description = "Optional static typing for Python"
optional = false
-python-versions = ">=3.8"
+python-versions = ">=3.9"
groups = ["dev"]
files = [
- {file = "mypy-1.7.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:12cce78e329838d70a204293e7b29af9faa3ab14899aec397798a4b41be7f340"},
- {file = "mypy-1.7.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:1484b8fa2c10adf4474f016e09d7a159602f3239075c7bf9f1627f5acf40ad49"},
- {file = "mypy-1.7.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:31902408f4bf54108bbfb2e35369877c01c95adc6192958684473658c322c8a5"},
- {file = "mypy-1.7.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:f2c2521a8e4d6d769e3234350ba7b65ff5d527137cdcde13ff4d99114b0c8e7d"},
- {file = "mypy-1.7.1-cp310-cp310-win_amd64.whl", hash = "sha256:fcd2572dd4519e8a6642b733cd3a8cfc1ef94bafd0c1ceed9c94fe736cb65b6a"},
- {file = "mypy-1.7.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:4b901927f16224d0d143b925ce9a4e6b3a758010673eeded9b748f250cf4e8f7"},
- {file = "mypy-1.7.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:2f7f6985d05a4e3ce8255396df363046c28bea790e40617654e91ed580ca7c51"},
- {file = "mypy-1.7.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:944bdc21ebd620eafefc090cdf83158393ec2b1391578359776c00de00e8907a"},
- {file = "mypy-1.7.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:9c7ac372232c928fff0645d85f273a726970c014749b924ce5710d7d89763a28"},
- {file = "mypy-1.7.1-cp311-cp311-win_amd64.whl", hash = "sha256:f6efc9bd72258f89a3816e3a98c09d36f079c223aa345c659622f056b760ab42"},
- {file = "mypy-1.7.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:6dbdec441c60699288adf051f51a5d512b0d818526d1dcfff5a41f8cd8b4aaf1"},
- {file = "mypy-1.7.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:4fc3d14ee80cd22367caaaf6e014494415bf440980a3045bf5045b525680ac33"},
- {file = "mypy-1.7.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2c6e4464ed5f01dc44dc9821caf67b60a4e5c3b04278286a85c067010653a0eb"},
- {file = "mypy-1.7.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:d9b338c19fa2412f76e17525c1b4f2c687a55b156320acb588df79f2e6fa9fea"},
- {file = "mypy-1.7.1-cp312-cp312-win_amd64.whl", hash = "sha256:204e0d6de5fd2317394a4eff62065614c4892d5a4d1a7ee55b765d7a3d9e3f82"},
- {file = "mypy-1.7.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:84860e06ba363d9c0eeabd45ac0fde4b903ad7aa4f93cd8b648385a888e23200"},
- {file = "mypy-1.7.1-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:8c5091ebd294f7628eb25ea554852a52058ac81472c921150e3a61cdd68f75a7"},
- {file = "mypy-1.7.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:40716d1f821b89838589e5b3106ebbc23636ffdef5abc31f7cd0266db936067e"},
- {file = "mypy-1.7.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:5cf3f0c5ac72139797953bd50bc6c95ac13075e62dbfcc923571180bebb662e9"},
- {file = "mypy-1.7.1-cp38-cp38-win_amd64.whl", hash = "sha256:78e25b2fd6cbb55ddfb8058417df193f0129cad5f4ee75d1502248e588d9e0d7"},
- {file = "mypy-1.7.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:75c4d2a6effd015786c87774e04331b6da863fc3fc4e8adfc3b40aa55ab516fe"},
- {file = "mypy-1.7.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:2643d145af5292ee956aa0a83c2ce1038a3bdb26e033dadeb2f7066fb0c9abce"},
- {file = "mypy-1.7.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:75aa828610b67462ffe3057d4d8a4112105ed211596b750b53cbfe182f44777a"},
- {file = "mypy-1.7.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:ee5d62d28b854eb61889cde4e1dbc10fbaa5560cb39780c3995f6737f7e82120"},
- {file = "mypy-1.7.1-cp39-cp39-win_amd64.whl", hash = "sha256:72cf32ce7dd3562373f78bd751f73c96cfb441de147cc2448a92c1a308bd0ca6"},
- {file = "mypy-1.7.1-py3-none-any.whl", hash = "sha256:f7c5d642db47376a0cc130f0de6d055056e010debdaf0707cd2b0fc7e7ef30ea"},
- {file = "mypy-1.7.1.tar.gz", hash = "sha256:fcb6d9afb1b6208b4c712af0dafdc650f518836065df0d4fb1d800f5d6773db2"},
-]
-
-[package.dependencies]
-mypy-extensions = ">=1.0.0"
-typing-extensions = ">=4.1.0"
+ {file = "mypy-1.15.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:979e4e1a006511dacf628e36fadfecbcc0160a8af6ca7dad2f5025529e082c13"},
+ {file = "mypy-1.15.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:c4bb0e1bd29f7d34efcccd71cf733580191e9a264a2202b0239da95984c5b559"},
+ {file = "mypy-1.15.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:be68172e9fd9ad8fb876c6389f16d1c1b5f100ffa779f77b1fb2176fcc9ab95b"},
+ {file = "mypy-1.15.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:c7be1e46525adfa0d97681432ee9fcd61a3964c2446795714699a998d193f1a3"},
+ {file = "mypy-1.15.0-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:2e2c2e6d3593f6451b18588848e66260ff62ccca522dd231cd4dd59b0160668b"},
+ {file = "mypy-1.15.0-cp310-cp310-win_amd64.whl", hash = "sha256:6983aae8b2f653e098edb77f893f7b6aca69f6cffb19b2cc7443f23cce5f4828"},
+ {file = "mypy-1.15.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:2922d42e16d6de288022e5ca321cd0618b238cfc5570e0263e5ba0a77dbef56f"},
+ {file = "mypy-1.15.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:2ee2d57e01a7c35de00f4634ba1bbf015185b219e4dc5909e281016df43f5ee5"},
+ {file = "mypy-1.15.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:973500e0774b85d9689715feeffcc980193086551110fd678ebe1f4342fb7c5e"},
+ {file = "mypy-1.15.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:5a95fb17c13e29d2d5195869262f8125dfdb5c134dc8d9a9d0aecf7525b10c2c"},
+ {file = "mypy-1.15.0-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:1905f494bfd7d85a23a88c5d97840888a7bd516545fc5aaedff0267e0bb54e2f"},
+ {file = "mypy-1.15.0-cp311-cp311-win_amd64.whl", hash = "sha256:c9817fa23833ff189db061e6d2eff49b2f3b6ed9856b4a0a73046e41932d744f"},
+ {file = "mypy-1.15.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:aea39e0583d05124836ea645f412e88a5c7d0fd77a6d694b60d9b6b2d9f184fd"},
+ {file = "mypy-1.15.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:2f2147ab812b75e5b5499b01ade1f4a81489a147c01585cda36019102538615f"},
+ {file = "mypy-1.15.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:ce436f4c6d218a070048ed6a44c0bbb10cd2cc5e272b29e7845f6a2f57ee4464"},
+ {file = "mypy-1.15.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:8023ff13985661b50a5928fc7a5ca15f3d1affb41e5f0a9952cb68ef090b31ee"},
+ {file = "mypy-1.15.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:1124a18bc11a6a62887e3e137f37f53fbae476dc36c185d549d4f837a2a6a14e"},
+ {file = "mypy-1.15.0-cp312-cp312-win_amd64.whl", hash = "sha256:171a9ca9a40cd1843abeca0e405bc1940cd9b305eaeea2dda769ba096932bb22"},
+ {file = "mypy-1.15.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:93faf3fdb04768d44bf28693293f3904bbb555d076b781ad2530214ee53e3445"},
+ {file = "mypy-1.15.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:811aeccadfb730024c5d3e326b2fbe9249bb7413553f15499a4050f7c30e801d"},
+ {file = "mypy-1.15.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:98b7b9b9aedb65fe628c62a6dc57f6d5088ef2dfca37903a7d9ee374d03acca5"},
+ {file = "mypy-1.15.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:c43a7682e24b4f576d93072216bf56eeff70d9140241f9edec0c104d0c515036"},
+ {file = "mypy-1.15.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:baefc32840a9f00babd83251560e0ae1573e2f9d1b067719479bfb0e987c6357"},
+ {file = "mypy-1.15.0-cp313-cp313-win_amd64.whl", hash = "sha256:b9378e2c00146c44793c98b8d5a61039a048e31f429fb0eb546d93f4b000bedf"},
+ {file = "mypy-1.15.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:e601a7fa172c2131bff456bb3ee08a88360760d0d2f8cbd7a75a65497e2df078"},
+ {file = "mypy-1.15.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:712e962a6357634fef20412699a3655c610110e01cdaa6180acec7fc9f8513ba"},
+ {file = "mypy-1.15.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:f95579473af29ab73a10bada2f9722856792a36ec5af5399b653aa28360290a5"},
+ {file = "mypy-1.15.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:8f8722560a14cde92fdb1e31597760dc35f9f5524cce17836c0d22841830fd5b"},
+ {file = "mypy-1.15.0-cp39-cp39-musllinux_1_2_x86_64.whl", hash = "sha256:1fbb8da62dc352133d7d7ca90ed2fb0e9d42bb1a32724c287d3c76c58cbaa9c2"},
+ {file = "mypy-1.15.0-cp39-cp39-win_amd64.whl", hash = "sha256:d10d994b41fb3497719bbf866f227b3489048ea4bbbb5015357db306249f7980"},
+ {file = "mypy-1.15.0-py3-none-any.whl", hash = "sha256:5469affef548bd1895d86d3bf10ce2b44e33d86923c29e4d675b3e323437ea3e"},
+ {file = "mypy-1.15.0.tar.gz", hash = "sha256:404534629d51d3efea5c800ee7c42b72a6554d6c400e6a79eafe15d11341fd43"},
+]
+
+[package.dependencies]
+mypy_extensions = ">=1.0.0"
+typing_extensions = ">=4.6.0"
[package.extras]
dmypy = ["psutil (>=4.0)"]
+faster-cache = ["orjson"]
install-types = ["pip"]
mypyc = ["setuptools (>=50)"]
reports = ["lxml"]
@@ -4927,18 +4935,6 @@ files = [
{file = "types_python_dateutil-2.9.0.20241206.tar.gz", hash = "sha256:18f493414c26ffba692a72369fea7a154c502646301ebfe3d56a04b3767284cb"},
]
-[[package]]
-name = "types-pytz"
-version = "2025.2.0.20250326"
-description = "Typing stubs for pytz"
-optional = false
-python-versions = ">=3.9"
-groups = ["dev"]
-files = [
- {file = "types_pytz-2025.2.0.20250326-py3-none-any.whl", hash = "sha256:3c397fd1b845cd2b3adc9398607764ced9e578a98a5d1fbb4a9bc9253edfb162"},
- {file = "types_pytz-2025.2.0.20250326.tar.gz", hash = "sha256:deda02de24f527066fc8d6a19e284ab3f3ae716a42b4adb6b40e75e408c08d36"},
-]
-
[[package]]
name = "types-pyyaml"
version = "6.0.12.20250402"
@@ -5620,4 +5616,4 @@ type = ["pytest-mypy"]
[metadata]
lock-version = "2.1"
python-versions = "~3.12"
-content-hash = "5225efcf9ed9697fa90a542e2c1a7ec466dd34ff70715d6cbd6df7d9b51afc06"
+content-hash = "1d99221538d816608e9a7b6f2676c28e4fd16583dc1d5b0e04c9b6b723081c4d"
diff --git a/pyproject.toml b/pyproject.toml
index e285c9e077..70bd237563 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -71,15 +71,15 @@ package-mode = false
cryptography = "^44.0.2"
dj-database-url = "^2"
dj-email-url = "^1"
- django = {version = "^4.2", extras = ["bcrypt"]}
+ django = {extras = ["bcrypt"], version = "^5.2"}
django-cache-url = "^3.1.2"
- django-celery-beat = "^2.2.1"
+ django-celery-beat = "^2.8.0"
django-countries = "^7.2"
django-filter = "^24.3"
django-measurement = "^3.0"
django-mptt = "^0"
django-phonenumber-field = ">=4,<9"
- django-stubs-ext = "^5.1.1"
+ django-stubs-ext = "^5.1.3"
draftjs-sanitizer = "^1.0.0"
faker = ">=26.0.0,<27.0"
google-cloud-pubsub = ">=1.7,<3.0"
@@ -148,7 +148,7 @@ package-mode = false
coverage = "^7.6"
deptry = "^0.23.0"
django-extensions = "^3.1.2"
- django-stubs = { version = "^4.2.7", extras = ["compatible-mypy"] }
+ django-stubs = {extras = ["compatible-mypy"], version = "^5.1.3"}
fakeredis = "^2.26"
freezegun = "^1"
mypy-extensions = "^1.0.0"
diff --git a/saleor/account/migrations/0087_alter_address_metadata_and_more.py b/saleor/account/migrations/0087_alter_address_metadata_and_more.py
new file mode 100644
index 0000000000..12638d93bb
--- /dev/null
+++ b/saleor/account/migrations/0087_alter_address_metadata_and_more.py
@@ -0,0 +1,54 @@
+# Generated by Django 5.2 on 2025-04-18 10:39
+
+from django.db import migrations, models
+
+import saleor.core.utils.json_serializer
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("account", "0086_auto_20240805_0851"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="address",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="address",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="user",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="user",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ ]
diff --git a/saleor/account/models.py b/saleor/account/models.py
index e3c8ba861d..f84bada34d 100644
--- a/saleor/account/models.py
+++ b/saleor/account/models.py
@@ -143,7 +143,7 @@ class UserManager(BaseUserManager["User"]):
group, created = Group.objects.get_or_create(name="Full Access")
if created:
group.permissions.add(*get_permissions())
- group.user_set.add(user) # type: ignore[attr-defined]
+ group.user_set.add(user)
return user
def customers(self):
diff --git a/saleor/app/migrations/0030_alter_app_metadata_alter_app_private_metadata.py b/saleor/app/migrations/0030_alter_app_metadata_alter_app_private_metadata.py
new file mode 100644
index 0000000000..1bbcdf38e1
--- /dev/null
+++ b/saleor/app/migrations/0030_alter_app_metadata_alter_app_private_metadata.py
@@ -0,0 +1,34 @@
+# Generated by Django 5.2 on 2025-04-18 10:39
+
+from django.db import migrations, models
+
+import saleor.core.utils.json_serializer
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("app", "0029_alter_app_identifier"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="app",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="app",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ ]
diff --git a/saleor/app/models.py b/saleor/app/models.py
index e375d1dd65..e153ba708f 100644
--- a/saleor/app/models.py
+++ b/saleor/app/models.py
@@ -125,7 +125,7 @@ class App(ModelWithMetadata):
class AppTokenManager(models.Manager["AppToken"]):
- def create(self, app, name="", auth_token=None, **extra_fields):
+ def create(self, *, app, name="", auth_token=None, **extra_fields): # type: ignore[override]
"""Create an app token with the given name."""
if not auth_token:
auth_token = generate_token()
@@ -134,11 +134,6 @@ class AppTokenManager(models.Manager["AppToken"]):
app_token.save()
return app_token, auth_token
- def create_with_token(self, *args, **kwargs) -> tuple["AppToken", str]:
- # As `create` is waiting to be fixed, I'm using this proper method from future
- # to get both AppToken and auth_token.
- return self.create(*args, **kwargs)
-
class AppToken(models.Model):
app = models.ForeignKey(App, on_delete=models.CASCADE, related_name="tokens")
diff --git a/saleor/app/tasks.py b/saleor/app/tasks.py
index 021afa70de..3d19bf50be 100644
--- a/saleor/app/tasks.py
+++ b/saleor/app/tasks.py
@@ -94,7 +94,7 @@ def remove_apps_task():
# Saleor needs to remove app by app to prevent timeouts
# on database when removing many deliveries.
- for app in apps.iterator():
+ for app in apps.iterator(chunk_size=1000):
webhooks = Webhook.objects.filter(app_id=app.id)
# Saleor uses batch size here to prevent timeouts on database.
diff --git a/saleor/attribute/migrations/0047_alter_attribute_page_types_and_more.py b/saleor/attribute/migrations/0047_alter_attribute_page_types_and_more.py
new file mode 100644
index 0000000000..13a1e604a9
--- /dev/null
+++ b/saleor/attribute/migrations/0047_alter_attribute_page_types_and_more.py
@@ -0,0 +1,58 @@
+# Generated by Django 5.2 on 2025-04-17 13:52
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("attribute", "0046_auto_20240611_1143"),
+ ("page", "0030_slug_translation_unique_constraint"),
+ ("product", "0198_alter_collection_products"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="attribute",
+ name="page_types",
+ field=models.ManyToManyField(
+ blank=True,
+ related_name="page_attributes",
+ through="attribute.AttributePage",
+ through_fields=("attribute", "page_type"),
+ to="page.pagetype",
+ ),
+ ),
+ migrations.AlterField(
+ model_name="attribute",
+ name="product_types",
+ field=models.ManyToManyField(
+ blank=True,
+ related_name="product_attributes",
+ through="attribute.AttributeProduct",
+ through_fields=("attribute", "product_type"),
+ to="product.producttype",
+ ),
+ ),
+ migrations.AlterField(
+ model_name="attribute",
+ name="product_variant_types",
+ field=models.ManyToManyField(
+ blank=True,
+ related_name="variant_attributes",
+ through="attribute.AttributeVariant",
+ through_fields=("attribute", "product_type"),
+ to="product.producttype",
+ ),
+ ),
+ migrations.AlterField(
+ model_name="attributevariant",
+ name="assigned_variants",
+ field=models.ManyToManyField(
+ blank=True,
+ related_name="attributesrelated",
+ through="attribute.AssignedVariantAttribute",
+ through_fields=("assignment", "variant"),
+ to="product.productvariant",
+ ),
+ ),
+ ]
diff --git a/saleor/attribute/migrations/0048_alter_attribute_metadata_and_more.py b/saleor/attribute/migrations/0048_alter_attribute_metadata_and_more.py
new file mode 100644
index 0000000000..ecffdeb72b
--- /dev/null
+++ b/saleor/attribute/migrations/0048_alter_attribute_metadata_and_more.py
@@ -0,0 +1,34 @@
+# Generated by Django 5.2 on 2025-04-18 10:39
+
+from django.db import migrations, models
+
+import saleor.core.utils.json_serializer
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("attribute", "0047_alter_attribute_page_types_and_more"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="attribute",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="attribute",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ ]
diff --git a/saleor/attribute/models/base.py b/saleor/attribute/models/base.py
index 650d11db28..d1aa54e840 100644
--- a/saleor/attribute/models/base.py
+++ b/saleor/attribute/models/base.py
@@ -243,7 +243,7 @@ class AttributeValueManager(models.Manager):
query = self._prepare_query_for_bulk_operation(objects_data)
# iterate over all records in db and check if they match any of objects data
- for record in query.iterator():
+ for record in query.iterator(chunk_size=1000):
# iterate over all objects data and check if they match any of records in db
for index, obj in objects_enumerated:
if self._is_correct_record(record, obj):
@@ -282,7 +282,7 @@ class AttributeValueManager(models.Manager):
query = self._prepare_query_for_bulk_operation(objects_data)
# iterate over all records in db and check if they match any of objects data
- for record in query.iterator():
+ for record in query.iterator(chunk_size=1000):
# iterate over all objects data and check if they match any of records in db
for index, obj in objects_enumerated:
if self._is_correct_record(record, obj):
@@ -321,7 +321,7 @@ class AttributeValueManager(models.Manager):
if objects_to_be_updated:
self.bulk_update(
objects_to_be_updated,
- fields=update_fields, # type: ignore[arg-type]
+ fields=update_fields,
)
return results
diff --git a/saleor/attribute/utils.py b/saleor/attribute/utils.py
index 934539acac..e3d3d90362 100644
--- a/saleor/attribute/utils.py
+++ b/saleor/attribute/utils.py
@@ -237,7 +237,7 @@ def _order_assigned_attr_values(
assignment_model.objects.filter(
Exists(values_qs.filter(id=OuterRef("value_id"))),
**instance_field_kwarg,
- ).iterator()
+ ).iterator(chunk_size=1000)
)
for value in assigned_values:
attribute_id = value_id_to_attribute_id[value.value_id]
diff --git a/saleor/celeryconf.py b/saleor/celeryconf.py
index 5878a48303..b793479b44 100644
--- a/saleor/celeryconf.py
+++ b/saleor/celeryconf.py
@@ -39,5 +39,5 @@ app.autodiscover_tasks(
],
related_name="saleor3_21",
)
-app.autodiscover_tasks(lambda: discover_plugins_modules(settings.PLUGINS)) # type: ignore[misc] # circular import # noqa: E501
+app.autodiscover_tasks(lambda: discover_plugins_modules(settings.PLUGINS))
app.autodiscover_tasks(related_name="search_tasks")
diff --git a/saleor/channel/migrations/0020_alter_channel_metadata_and_more.py b/saleor/channel/migrations/0020_alter_channel_metadata_and_more.py
new file mode 100644
index 0000000000..e99a1ec29d
--- /dev/null
+++ b/saleor/channel/migrations/0020_alter_channel_metadata_and_more.py
@@ -0,0 +1,34 @@
+# Generated by Django 5.2 on 2025-04-18 10:39
+
+from django.db import migrations, models
+
+import saleor.core.utils.json_serializer
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("channel", "0019_channel_draft_order_line_price_freeze_period"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="channel",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="channel",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ ]
diff --git a/saleor/channel/migrations/0021_merge_20250423_1021.py b/saleor/channel/migrations/0021_merge_20250423_1021.py
new file mode 100644
index 0000000000..514785d9ed
--- /dev/null
+++ b/saleor/channel/migrations/0021_merge_20250423_1021.py
@@ -0,0 +1,12 @@
+# Generated by Django 5.2 on 2025-04-23 10:21
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("channel", "0020_alter_channel_metadata_and_more"),
+ ("channel", "0020_channel_use_legacy_line_voucher_propagation_for_order"),
+ ]
+
+ operations = []
diff --git a/saleor/channel/migrations/0022_merge_20250527_1210.py b/saleor/channel/migrations/0022_merge_20250527_1210.py
new file mode 100644
index 0000000000..e22d8bfb4b
--- /dev/null
+++ b/saleor/channel/migrations/0022_merge_20250527_1210.py
@@ -0,0 +1,15 @@
+# Generated by Django 5.2 on 2025-05-27 12:10
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("channel", "0021_merge_20250423_1021"),
+ (
+ "channel",
+ "0021_rename_use_legacy_line_voucher_propagation_for_order_channel_use_legacy_line_discount_propagation_fo",
+ ),
+ ]
+
+ operations = []
diff --git a/saleor/checkout/fetch.py b/saleor/checkout/fetch.py
index 9e6446ade8..0eb477b77e 100644
--- a/saleor/checkout/fetch.py
+++ b/saleor/checkout/fetch.py
@@ -578,7 +578,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: # type: ignore[attr-defined]
+ if channel_listing.channel_id == channel_id:
product_channel_listing = channel_listing
product_channel_listing_mapping[product.id] = product_channel_listing
return product_channel_listing
diff --git a/saleor/checkout/migrations/0078_alter_checkoutline_metadata_and_more.py b/saleor/checkout/migrations/0078_alter_checkoutline_metadata_and_more.py
new file mode 100644
index 0000000000..96c73a4247
--- /dev/null
+++ b/saleor/checkout/migrations/0078_alter_checkoutline_metadata_and_more.py
@@ -0,0 +1,54 @@
+# Generated by Django 5.2 on 2025-04-18 10:39
+
+from django.db import migrations, models
+
+import saleor.core.utils.json_serializer
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("checkout", "0077_merge_20250303_0958"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="checkoutline",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="checkoutline",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="checkoutmetadata",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="checkoutmetadata",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ ]
diff --git a/saleor/checkout/migrations/0080_merge_20250527_1210.py b/saleor/checkout/migrations/0080_merge_20250527_1210.py
new file mode 100644
index 0000000000..af5afe4bed
--- /dev/null
+++ b/saleor/checkout/migrations/0080_merge_20250527_1210.py
@@ -0,0 +1,12 @@
+# Generated by Django 5.2 on 2025-05-27 12:10
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("checkout", "0078_alter_checkoutline_metadata_and_more"),
+ ("checkout", "0079_alter_checkoutline_prior_unit_price_amount_and_more"),
+ ]
+
+ operations = []
diff --git a/saleor/core/db/fields.py b/saleor/core/db/fields.py
index 1e79efd34b..fcbf1dc135 100644
--- a/saleor/core/db/fields.py
+++ b/saleor/core/db/fields.py
@@ -40,6 +40,7 @@ class NonDatabaseFieldBase:
blank = True
concrete = False
editable = False
+ generated = True
unique = False
is_relation = False
diff --git a/saleor/core/db/tests/test_postgres_json_concatenate.py b/saleor/core/db/tests/test_postgres_json_concatenate.py
index e3ef954f29..e84a0375ba 100644
--- a/saleor/core/db/tests/test_postgres_json_concatenate.py
+++ b/saleor/core/db/tests/test_postgres_json_concatenate.py
@@ -71,44 +71,6 @@ def test_save_concat_new_dict(checkout, checkout_metadata_qs):
assert metadata.metadata == new_dict
-def test_save_concat_new_dict_null_value_in_db(checkout, checkout_metadata_qs):
- # given
- checkout.metadata_storage.metadata = None
- checkout.metadata_storage.save()
- new_dict = {"new-key": "new"}
-
- # when
- checkout_metadata_qs.update(
- metadata=PostgresJsonConcatenate(
- F("metadata"), Value(new_dict, output_field=JSONField())
- )
- )
-
- # then
- metadata = checkout.metadata_storage
- metadata.refresh_from_db()
- assert metadata.metadata == new_dict
-
-
-def test_save_concat_null_value_in_db(checkout, checkout_metadata_qs):
- # given
- checkout.metadata_storage.metadata = None
- checkout.metadata_storage.save()
- new_dict = None
-
- # when
- checkout_metadata_qs.update(
- metadata=PostgresJsonConcatenate(
- F("metadata"), Value(new_dict, output_field=JSONField())
- )
- )
-
- # then
- metadata = checkout.metadata_storage
- metadata.refresh_from_db()
- assert metadata.metadata == {}
-
-
def test_save_concat_with_none_value(checkout, checkout_metadata_qs):
# given
checkout.metadata_storage.metadata = TEST_DICT
diff --git a/saleor/core/models.py b/saleor/core/models.py
index ba97a97659..9e00687a68 100644
--- a/saleor/core/models.py
+++ b/saleor/core/models.py
@@ -79,9 +79,11 @@ class PublishableModel(models.Model):
class ModelWithMetadata(models.Model):
private_metadata = JSONField(
- blank=True, null=True, default=dict, encoder=CustomJsonEncoder
+ blank=True, db_default={}, default=dict, encoder=CustomJsonEncoder
+ )
+ metadata = JSONField(
+ blank=True, db_default={}, default=dict, encoder=CustomJsonEncoder
)
- metadata = JSONField(blank=True, null=True, default=dict, encoder=CustomJsonEncoder)
class Meta:
indexes: list[PostgresIndex] = [
diff --git a/saleor/core/utils/random_data.py b/saleor/core/utils/random_data.py
index 265a1c1df5..83f2a3b3b8 100644
--- a/saleor/core/utils/random_data.py
+++ b/saleor/core/utils/random_data.py
@@ -966,7 +966,7 @@ def create_staffs(staff_password):
def create_group(name, permissions, users):
group, _ = Group.objects.get_or_create(name=name)
group.permissions.add(*permissions)
- group.user_set.add(*users) # type: ignore[attr-defined]
+ group.user_set.add(*users)
return group
diff --git a/saleor/csv/tests/export/products_data/utils.py b/saleor/csv/tests/export/products_data/utils.py
index dcbbf4072f..f6e429a9a3 100644
--- a/saleor/csv/tests/export/products_data/utils.py
+++ b/saleor/csv/tests/export/products_data/utils.py
@@ -21,7 +21,7 @@ def add_product_attribute_data_to_expected_data(data, product, attribute_ids, pk
Exists(product_attributes.filter(attribute_id=OuterRef("id")))
)
.order_by("attributeproduct__sort_order")
- .iterator()
+ .iterator(chunk_size=1000)
)
assigned_values = AssignedProductAttributeValue.objects.filter(
product_id=product.pk
diff --git a/saleor/csv/utils/products_data.py b/saleor/csv/utils/products_data.py
index 0c5374313c..2baedce76d 100644
--- a/saleor/csv/utils/products_data.py
+++ b/saleor/csv/utils/products_data.py
@@ -145,7 +145,7 @@ def prepare_products_relations_data(
relations_data = queryset.values(*fields)
- for data in relations_data.iterator():
+ for data in relations_data.iterator(chunk_size=1000):
pk = data.get("pk")
collection = data.get("collections__slug")
image = data.pop("media__image", None)
@@ -184,7 +184,7 @@ def prepare_products_relations_data(
)
fields_for_attrs.update(attribute_fields.values())
relations_data = relations_data.values(*fields_for_attrs)
- for data in relations_data.iterator():
+ for data in relations_data.iterator(chunk_size=1000):
pk = data.get("pk")
result_data, data = handle_attribute_data(
pk,
@@ -251,7 +251,7 @@ def prepare_variants_relations_data(
relations_data = queryset.values(*fields)
- for data in relations_data.iterator():
+ for data in relations_data.iterator(chunk_size=1000):
pk = data.get("variants__pk")
image = data.pop("variants__media__image", None)
diff --git a/saleor/discount/migrations/0085_alter_promotion_metadata_and_more.py b/saleor/discount/migrations/0085_alter_promotion_metadata_and_more.py
new file mode 100644
index 0000000000..b4df0653fb
--- /dev/null
+++ b/saleor/discount/migrations/0085_alter_promotion_metadata_and_more.py
@@ -0,0 +1,54 @@
+# Generated by Django 5.2 on 2025-04-18 10:39
+
+from django.db import migrations, models
+
+import saleor.core.utils.json_serializer
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("discount", "0084_set_missing_currency"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="promotion",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="promotion",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="voucher",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="voucher",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ ]
diff --git a/saleor/discount/migrations/0086_merge_20250527_1210.py b/saleor/discount/migrations/0086_merge_20250527_1210.py
new file mode 100644
index 0000000000..86e0048765
--- /dev/null
+++ b/saleor/discount/migrations/0086_merge_20250527_1210.py
@@ -0,0 +1,12 @@
+# Generated by Django 5.2 on 2025-05-27 12:10
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("discount", "0085_alter_checkoutdiscount_amount_value_and_more"),
+ ("discount", "0085_alter_promotion_metadata_and_more"),
+ ]
+
+ operations = []
diff --git a/saleor/discount/utils/order.py b/saleor/discount/utils/order.py
index af4ca44776..fd7e3f7462 100644
--- a/saleor/discount/utils/order.py
+++ b/saleor/discount/utils/order.py
@@ -254,6 +254,10 @@ def _create_order_line_discount_for_catalogue_promotion(
line: OrderLine, rule_info: VariantPromotionRuleInfo, channel: Channel
):
rule = rule_info.rule
+ if rule.reward_value_type is None or rule.reward_value is None:
+ raise ValueError(
+ "Reward value type and reward value cannot be NULL for catalogue promotions."
+ )
rule_discount_amount = _get_rule_discount_amount(line, rule_info, channel)
discount_name = get_discount_name(rule, rule_info.promotion)
translated_name = get_discount_translated_name(rule_info)
diff --git a/saleor/discount/utils/promotion.py b/saleor/discount/utils/promotion.py
index c067416d89..70fbe44e06 100644
--- a/saleor/discount/utils/promotion.py
+++ b/saleor/discount/utils/promotion.py
@@ -522,7 +522,7 @@ def get_variants_to_promotion_rules_map(
rule_to_channel_ids_map = _get_rule_to_channel_ids_map(rules)
rules_in_bulk = rules.in_bulk()
- for promotion_rule_variant in promotion_rule_variants.iterator():
+ for promotion_rule_variant in promotion_rule_variants.iterator(chunk_size=1000):
rule_id = promotion_rule_variant.promotionrule_id
rule = rules_in_bulk.get(rule_id)
# there is no rule when it is a part of inactive promotion
@@ -563,7 +563,7 @@ def fetch_promotion_rules_for_checkout_or_order(
qs = instance._meta.model.objects.using(database_connection_name).filter( # type: ignore[attr-defined] # noqa: E501
pk=instance.pk
)
- for rule in rules.iterator():
+ for rule in rules.iterator(chunk_size=1000):
rule_channel_ids = rule_to_channel_ids_map.get(rule.id, [])
if channel_id not in rule_channel_ids:
continue
@@ -819,7 +819,7 @@ def _handle_gift_reward(
(
line_discount,
discount_created,
- ) = discount_model.objects.get_or_create( # type: ignore[attr-defined]
+ ) = discount_model.objects.get_or_create(
type=DiscountType.ORDER_PROMOTION,
line=line,
defaults=asdict(line_discount_data),
@@ -868,7 +868,7 @@ def _handle_gift_reward(
line_info for line_info in lines_info if line_info.line.pk == line.id
)
line_info.line = line
- line_info.discounts = [line_discount]
+ line_info.discounts = [line_discount] # type: ignore[assignment]
def get_active_catalogue_promotion_rules(
diff --git a/saleor/giftcard/migrations/0021_alter_giftcard_metadata_and_more.py b/saleor/giftcard/migrations/0021_alter_giftcard_metadata_and_more.py
new file mode 100644
index 0000000000..734bc1c116
--- /dev/null
+++ b/saleor/giftcard/migrations/0021_alter_giftcard_metadata_and_more.py
@@ -0,0 +1,34 @@
+# Generated by Django 5.2 on 2025-04-18 10:39
+
+from django.db import migrations, models
+
+import saleor.core.utils.json_serializer
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("giftcard", "0020_search_vector_index"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="giftcard",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="giftcard",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ ]
diff --git a/saleor/giftcard/migrations/0022_merge_20250527_1210.py b/saleor/giftcard/migrations/0022_merge_20250527_1210.py
new file mode 100644
index 0000000000..4f9ad65b77
--- /dev/null
+++ b/saleor/giftcard/migrations/0022_merge_20250527_1210.py
@@ -0,0 +1,12 @@
+# Generated by Django 5.2 on 2025-05-27 12:10
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("giftcard", "0021_alter_giftcard_current_balance_amount_and_more"),
+ ("giftcard", "0021_alter_giftcard_metadata_and_more"),
+ ]
+
+ operations = []
diff --git a/saleor/graphql/account/types.py b/saleor/graphql/account/types.py
index 7835b37121..a04f7ac64c 100644
--- a/saleor/graphql/account/types.py
+++ b/saleor/graphql/account/types.py
@@ -988,7 +988,7 @@ class Group(ModelObjectType[models.Group]):
@staticmethod
def resolve_users(root: models.Group, info: ResolveInfo):
database_connection_name = get_database_connection_name(info.context)
- return root.user_set.using(database_connection_name).all() # type: ignore[attr-defined]
+ return root.user_set.using(database_connection_name).all()
@staticmethod
def resolve_permissions(root: models.Group, info: ResolveInfo):
diff --git a/saleor/graphql/account/utils.py b/saleor/graphql/account/utils.py
index 9a0751f97b..f1e30dee86 100644
--- a/saleor/graphql/account/utils.py
+++ b/saleor/graphql/account/utils.py
@@ -110,7 +110,7 @@ def get_group_permission_codes(group: Group) -> "QuerySet":
"""Return group permissions in the format '<app label>.<permission codename>'."""
return group.permissions.annotate(
formatted_codename=Concat("content_type__app_label", Value("."), "codename")
- ).values_list("formatted_codename", flat=True) # type: ignore[misc]
+ ).values_list("formatted_codename", flat=True)
def get_groups_which_user_can_manage(
@@ -131,7 +131,7 @@ def get_groups_which_user_can_manage(
)
editable_groups: list[Group] = []
- for group in groups.iterator():
+ for group in groups.iterator(chunk_size=1000):
out_of_scope_permissions = set(group.group_perms) - user_permission_pks
out_of_scope_permissions.discard(None)
if not out_of_scope_permissions:
@@ -207,7 +207,7 @@ def get_not_manageable_permissions_after_removing_users_from_group(
After removing users from group, for each permission, there should be at least
one staff member who can manage it (has both “manage staff” and this permission).
"""
- group_users = group.user_set.all() # type: ignore[attr-defined]
+ group_users = group.user_set.all()
group_permissions = group.permissions.values_list("codename", flat=True)
# if group has manage_staff permission and some users will stay in group
# given users can me removed (permissions will be manageable)
@@ -293,8 +293,9 @@ def get_group_to_permissions_and_users_mapping():
"permissions__codename",
),
filter=Q(permissions__isnull=False),
+ default=[],
),
- users=ArrayAgg("user", filter=Q(user__is_active=True)),
+ users=ArrayAgg("user", filter=Q(user__is_active=True), default=[]),
)
.values("pk", "perm_codenames", "users")
)
diff --git a/saleor/graphql/api.py b/saleor/graphql/api.py
index 47d123e519..63891f01a8 100644
--- a/saleor/graphql/api.py
+++ b/saleor/graphql/api.py
@@ -208,7 +208,7 @@ class SaleorGraphQLBackend(GraphQLCoreBackend):
schema=schema,
document_string=document_string,
document_ast=document_ast,
- execute=partial(execute, schema, document_ast, **self.execute_params),
+ execute=partial(execute, schema, document_ast, **self.execute_params), # type: ignore[arg-type]
)
diff --git a/saleor/graphql/app/dataloaders/app_extension.py b/saleor/graphql/app/dataloaders/app_extension.py
index 9c6c84a782..58e2aed415 100644
--- a/saleor/graphql/app/dataloaders/app_extension.py
+++ b/saleor/graphql/app/dataloaders/app_extension.py
@@ -23,7 +23,7 @@ class AppExtensionByAppIdLoader(DataLoader[str, AppExtension]):
)
extensions_map = defaultdict(list)
app_extension_loader = AppExtensionByIdLoader(self.context)
- for extension in extensions.iterator():
+ for extension in extensions.iterator(chunk_size=1000):
extensions_map[extension.app_id].append(extension)
app_extension_loader.prime(extension.id, extension)
return [extensions_map.get(app_id, []) for app_id in keys]
diff --git a/saleor/graphql/attribute/dataloaders.py b/saleor/graphql/attribute/dataloaders.py
index 63226ec227..58faae0f70 100644
--- a/saleor/graphql/attribute/dataloaders.py
+++ b/saleor/graphql/attribute/dataloaders.py
@@ -12,7 +12,7 @@ class AttributeValuesByAttributeIdLoader(DataLoader[int, list[AttributeValue]]):
self.database_connection_name
).filter(attribute_id__in=keys)
attribute_to_attributevalues = defaultdict(list)
- for attribute_value in attribute_values.iterator():
+ for attribute_value in attribute_values.iterator(chunk_size=1000):
attribute_to_attributevalues[attribute_value.attribute_id].append(
attribute_value
)
diff --git a/saleor/graphql/attribute/types.py b/saleor/graphql/attribute/types.py
index a00e285513..fcf64e49c2 100644
--- a/saleor/graphql/attribute/types.py
+++ b/saleor/graphql/attribute/types.py
@@ -1,7 +1,4 @@
-from typing import cast
-
import graphene
-from django.db.models import QuerySet
from ...attribute import AttributeInputType, models
from ...permission.enums import (
@@ -270,14 +267,9 @@ class Attribute(ModelObjectType[models.Attribute]):
@staticmethod
def resolve_choices(root: models.Attribute, info: ResolveInfo, **kwargs):
if root.input_type in AttributeInputType.TYPES_WITH_CHOICES:
- qs = cast(
- QuerySet[models.AttributeValue],
- root.values.using(get_database_connection_name(info.context)).all(),
- )
+ qs = root.values.using(get_database_connection_name(info.context)).all()
else:
- qs = cast(
- QuerySet[models.AttributeValue], models.AttributeValue.objects.none()
- )
+ qs = models.AttributeValue.objects.none()
qs = filter_connection_queryset(
qs, kwargs, allow_replica=info.context.allow_replica
diff --git a/saleor/graphql/attribute/utils.py b/saleor/graphql/attribute/utils.py
index 4a56a93faa..75a9f3cd6b 100644
--- a/saleor/graphql/attribute/utils.py
+++ b/saleor/graphql/attribute/utils.py
@@ -124,7 +124,7 @@ class AttributeAssignmentMixin:
nodes: list[attribute_models.Attribute] = list(
qs.filter(
Q(pk__in=pks) | Q(external_reference__in=external_references)
- ).iterator()
+ ).iterator(chunk_size=1000)
)
if not nodes:
diff --git a/saleor/graphql/checkout/dataloaders/models.py b/saleor/graphql/checkout/dataloaders/models.py
index 12f0ee21fe..61bd0de354 100644
--- a/saleor/graphql/checkout/dataloaders/models.py
+++ b/saleor/graphql/checkout/dataloaders/models.py
@@ -73,7 +73,7 @@ class CheckoutLinesByCheckoutTokenLoader(DataLoader[str, list[CheckoutLine]]):
checkout_id__in=keys
)
line_map = defaultdict(list)
- for line in lines.iterator():
+ for line in lines.iterator(chunk_size=1000):
line_map[line.checkout_id].append(line)
return [line_map.get(checkout_id, []) for checkout_id in keys]
diff --git a/saleor/graphql/checkout/tests/benchmark/test_checkout_mutations.py b/saleor/graphql/checkout/tests/benchmark/test_checkout_mutations.py
index 8c85761971..961a43bbb8 100644
--- a/saleor/graphql/checkout/tests/benchmark/test_checkout_mutations.py
+++ b/saleor/graphql/checkout/tests/benchmark/test_checkout_mutations.py
@@ -572,7 +572,7 @@ def test_create_checkout_with_order_promotion(
# when
user_api_client.ensure_access_token()
- with django_assert_num_queries(88):
+ with django_assert_num_queries(89):
response = user_api_client.post_graphql(MUTATION_CHECKOUT_CREATE, variables)
# then
@@ -1289,7 +1289,7 @@ def test_add_checkout_lines_order_discount_applies(
# when
user_api_client.ensure_access_token()
- with django_assert_num_queries(97):
+ with django_assert_num_queries(99):
response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
# then
@@ -1324,7 +1324,7 @@ def test_add_checkout_lines_gift_discount_applies(
# when
user_api_client.ensure_access_token()
- with django_assert_num_queries(124):
+ with django_assert_num_queries(126):
response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
# then
diff --git a/saleor/graphql/core/tests/test_core_reordering.py b/saleor/graphql/core/tests/test_core_reordering.py
index 325081f636..5768108fb0 100644
--- a/saleor/graphql/core/tests/test_core_reordering.py
+++ b/saleor/graphql/core/tests/test_core_reordering.py
@@ -225,11 +225,10 @@ def test_reordering_concurrently(dummy_attribute, assert_num_queries):
perform_reordering(qs, operations)
assert ctx[0]["sql"] == (
- 'SELECT "attribute_attributevalue"."id", '
- '"attribute_attributevalue"."sort_order" '
+ 'SELECT "attribute_attributevalue"."id" AS "pk", '
+ '"attribute_attributevalue"."sort_order" AS "sort_order" '
'FROM "attribute_attributevalue" '
- "ORDER BY "
- '"attribute_attributevalue"."sort_order" ASC NULLS LAST, '
+ "ORDER BY 2 ASC NULLS LAST, "
'"attribute_attributevalue"."id" ASC FOR UPDATE'
)
assert ctx[1]["sql"] == (
diff --git a/saleor/graphql/core/utils/reordering.py b/saleor/graphql/core/utils/reordering.py
index 5161256104..8a30f890f6 100644
--- a/saleor/graphql/core/utils/reordering.py
+++ b/saleor/graphql/core/utils/reordering.py
@@ -21,6 +21,9 @@ class FinalSortOrder:
def _prepare_related_fields_for_save(self, operation_name, fields=None):
pass
+ def _is_pk_set(self):
+ return self.pk is not None
+
class Reordering:
def __init__(
diff --git a/saleor/graphql/discount/utils.py b/saleor/graphql/discount/utils.py
index 8c34b70590..98d5a0e8ee 100644
--- a/saleor/graphql/discount/utils.py
+++ b/saleor/graphql/discount/utils.py
@@ -204,8 +204,6 @@ def filter_qs_by_predicate(
if result_qs is None:
result_qs = base_qs
- result_qs = cast(QuerySet, result_qs)
-
and_data: list[dict] | None = predicate.pop("AND", None)
or_data: list[dict] | None = predicate.pop("OR", None)
@@ -222,7 +220,7 @@ def filter_qs_by_predicate(
result_qs, base_qs, predicate, Operators.AND, predicate_type, currency
)
- return result_qs
+ return result_qs # type: ignore[return-value]
def _handle_and_data(
diff --git a/saleor/graphql/giftcard/bulk_mutations/gift_card_bulk_create.py b/saleor/graphql/giftcard/bulk_mutations/gift_card_bulk_create.py
index 29c39dcdd7..3acb3f5df1 100644
--- a/saleor/graphql/giftcard/bulk_mutations/gift_card_bulk_create.py
+++ b/saleor/graphql/giftcard/bulk_mutations/gift_card_bulk_create.py
@@ -169,7 +169,7 @@ class GiftCardBulkCreate(BaseMutation):
models.GiftCardTag.objects.bulk_create(
[models.GiftCardTag(name=tag) for tag in tags_to_create]
)
- for tag_instance in tags_instances.iterator():
+ for tag_instance in tags_instances.iterator(chunk_size=1000):
tag_instance.gift_cards.set(instances)
@classmethod
diff --git a/saleor/graphql/giftcard/dataloaders.py b/saleor/graphql/giftcard/dataloaders.py
index 3ecda73da8..2e49a05062 100644
--- a/saleor/graphql/giftcard/dataloaders.py
+++ b/saleor/graphql/giftcard/dataloaders.py
@@ -28,7 +28,7 @@ class GiftCardEventsByGiftCardIdLoader(DataLoader[int, list[GiftCardEvent]]):
gift_card_id__in=keys
)
events_map = defaultdict(list)
- for event in events.iterator():
+ for event in events.iterator(chunk_size=1000):
events_map[event.gift_card_id].append(event)
return [events_map.get(gift_card_id, []) for gift_card_id in keys]
diff --git a/saleor/graphql/meta/resolvers.py b/saleor/graphql/meta/resolvers.py
index 34d4cc3f24..1ab80f615e 100644
--- a/saleor/graphql/meta/resolvers.py
+++ b/saleor/graphql/meta/resolvers.py
@@ -1,6 +1,8 @@
import dataclasses
from operator import itemgetter
+from django.db import models
+
from ...account import models as account_models
from ...app import models as app_models
from ...attribute import models as attribute_models
@@ -47,7 +49,7 @@ def resolve_object_with_metadata_type(instance):
from ..tax import types as tax_types
from ..warehouse import types as warehouse_types
- MODEL_TO_TYPE_MAP = {
+ MODEL_TO_TYPE_MAP: dict[type, type[models.Model]] = {
account_models.Address: account_types.Address,
account_models.User: account_types.User,
app_models.App: app_types.App,
@@ -89,11 +91,20 @@ def resolve_object_with_metadata_type(instance):
instance, "old_sale_id", False
):
return discount_types.Sale, instance.pk
- return MODEL_TO_TYPE_MAP.get(instance.__class__, None), instance.pk
+ if instance.__class__ not in MODEL_TO_TYPE_MAP:
+ raise ValueError(f"Unknown type: {instance.__class__}")
+ return MODEL_TO_TYPE_MAP[instance.__class__], instance.pk
if dataclasses.is_dataclass(instance):
- DATACLASS_TO_TYPE_MAP = {ShippingMethodData: shipping_types.ShippingMethod}
- return DATACLASS_TO_TYPE_MAP.get(instance.__class__, None), instance.id
+ DATACLASS_TO_TYPE_MAP: dict[type, type[models.Model]] = {
+ ShippingMethodData: shipping_types.ShippingMethod
+ }
+ if isinstance(instance, type):
+ raise ValueError(f"Unknown type: {instance}")
+ if instance.__class__ not in DATACLASS_TO_TYPE_MAP:
+ raise ValueError(f"Unknown type: {instance.__class__}")
+ return DATACLASS_TO_TYPE_MAP[instance.__class__], instance.id # type: ignore[attr-defined]
+
raise ValueError(f"Unknown type: {instance.__class__}")
diff --git a/saleor/graphql/order/dataloaders.py b/saleor/graphql/order/dataloaders.py
index 8aff0b6a19..5a0dd994aa 100644
--- a/saleor/graphql/order/dataloaders.py
+++ b/saleor/graphql/order/dataloaders.py
@@ -99,7 +99,7 @@ class OrderLinesByOrderIdLoader(DataLoader[UUID, list[OrderLine]]):
.order_by("created_at")
)
line_map = defaultdict(list)
- for line in lines.iterator():
+ for line in lines.iterator(chunk_size=1000):
line_map[line.order_id].append(line)
return [line_map.get(order_id, []) for order_id in keys]
@@ -114,7 +114,7 @@ class OrderEventsByOrderIdLoader(DataLoader[UUID, list[OrderEvent]]):
.order_by("pk")
)
events_map = defaultdict(list)
- for event in events.iterator():
+ for event in events.iterator(chunk_size=1000):
events_map[event.order_id].append(event)
return [events_map.get(order_id, []) for order_id in keys]
@@ -140,7 +140,7 @@ class OrderGrantedRefundsByOrderIdLoader(DataLoader[UUID, list[OrderGrantedRefun
).filter(order_id__in=keys)
refunds_map = defaultdict(list)
- for refund in refunds.iterator():
+ for refund in refunds.iterator(chunk_size=1000):
refunds_map[refund.order_id].append(refund)
return [refunds_map.get(order_id, []) for order_id in keys]
@@ -156,7 +156,7 @@ class OrderGrantedRefundLinesByOrderGrantedRefundIdLoader(
).filter(granted_refund_id__in=keys)
refund_lines_map = defaultdict(list)
- for refund_line in refund_lines.iterator():
+ for refund_line in refund_lines.iterator(chunk_size=1000):
refund_lines_map[refund_line.granted_refund_id].append(refund_line)
return [
refund_lines_map.get(granted_refund_id, []) for granted_refund_id in keys
@@ -188,7 +188,7 @@ class FulfillmentsByOrderIdLoader(DataLoader[UUID, list[Fulfillment]]):
.order_by("pk")
)
fulfillments_map = defaultdict(list)
- for fulfillment in fulfillments.iterator():
+ for fulfillment in fulfillments.iterator(chunk_size=1000):
fulfillments_map[fulfillment.order_id].append(fulfillment)
return [fulfillments_map.get(order_id, []) for order_id in keys]
diff --git a/saleor/graphql/page/dataloaders.py b/saleor/graphql/page/dataloaders.py
index 6cf8f1b31f..388605010c 100644
--- a/saleor/graphql/page/dataloaders.py
+++ b/saleor/graphql/page/dataloaders.py
@@ -114,7 +114,7 @@ class BaseAttributeValuesByPageIdLoader(DataLoader[int, list[dict]]):
attribute_values = list(
AssignedPageAttributeValue.objects.using(self.database_connection_name)
.filter(page_id__in=keys)
- .iterator()
+ .iterator(chunk_size=1000)
)
value_ids = [a.value_id for a in attribute_values]
diff --git a/saleor/graphql/page/mutations/page_type_update.py b/saleor/graphql/page/mutations/page_type_update.py
index 108be15de2..cad2f08029 100644
--- a/saleor/graphql/page/mutations/page_type_update.py
+++ b/saleor/graphql/page/mutations/page_type_update.py
@@ -58,7 +58,7 @@ class PageTypeUpdate(PageTypeMixin, DeprecatedModelMutation):
instance, "name", cleaned_input
)
except ValidationError as error:
- error.code = PageErrorCode.REQUIRED
+ error.code = PageErrorCode.REQUIRED.value
errors["slug"].append(error)
add_attributes = cleaned_input.get("add_attributes")
diff --git a/saleor/graphql/product/bulk_mutations/collection_bulk_delete.py b/saleor/graphql/product/bulk_mutations/collection_bulk_delete.py
index c18525d4bb..fa3ff1d136 100644
--- a/saleor/graphql/product/bulk_mutations/collection_bulk_delete.py
+++ b/saleor/graphql/product/bulk_mutations/collection_bulk_delete.py
@@ -40,7 +40,7 @@ class CollectionBulkDelete(ModelBulkDeleteMutation):
)
manager = get_plugin_manager_promise(info.context).get()
webhooks = get_webhooks_for_event(WebhookEventAsyncType.COLLECTION_DELETED)
- for collection in queryset.iterator():
+ for collection in queryset.iterator(chunk_size=1000):
cls.call_event(manager.collection_deleted, collection, webhooks=webhooks)
queryset.delete()
diff --git a/saleor/graphql/product/dataloaders/attributes.py b/saleor/graphql/product/dataloaders/attributes.py
index a027691dd5..f24a8de313 100644
--- a/saleor/graphql/product/dataloaders/attributes.py
+++ b/saleor/graphql/product/dataloaders/attributes.py
@@ -138,7 +138,7 @@ class AttributeVariantsByProductTypeIdLoader(DataLoader):
)
attribute_variants = qs.filter(product_type_id__in=keys)
producttype_to_attributevariants = defaultdict(list)
- for attribute_variant in attribute_variants.iterator():
+ for attribute_variant in attribute_variants.iterator(chunk_size=1000):
producttype_to_attributevariants[attribute_variant.product_type_id].append(
attribute_variant
)
@@ -166,7 +166,9 @@ class AssignedVariantAttributesByProductVariantId(DataLoader):
"assignment__attribute"
)
variant_attributes = defaultdict(list)
- for assigned_variant_attribute in assigned_variant_attributes.iterator():
+ for assigned_variant_attribute in assigned_variant_attributes.iterator(
+ chunk_size=1000
+ ):
variant_attributes[assigned_variant_attribute.variant_id].append(
assigned_variant_attribute
)
@@ -180,7 +182,7 @@ class AttributeValuesByAssignedVariantAttributeIdLoader(DataLoader):
attribute_values = list(
AssignedVariantAttributeValue.objects.using(self.database_connection_name)
.filter(assignment_id__in=keys)
- .iterator()
+ .iterator(chunk_size=1000)
)
value_ids = [a.value_id for a in attribute_values]
@@ -211,7 +213,7 @@ class BaseAttributeValuesByProductIdLoader(DataLoader):
attribute_values = list(
AssignedProductAttributeValue.objects.using(self.database_connection_name)
.filter(product_id__in=keys)
- .iterator()
+ .iterator(chunk_size=1000)
)
value_ids = [a.value_id for a in attribute_values]
diff --git a/saleor/graphql/product/dataloaders/products.py b/saleor/graphql/product/dataloaders/products.py
index 0fec5b3c22..f69b4e69cb 100644
--- a/saleor/graphql/product/dataloaders/products.py
+++ b/saleor/graphql/product/dataloaders/products.py
@@ -84,7 +84,9 @@ class ProductChannelListingByProductIdLoader(DataLoader[int, ProductChannelListi
self.database_connection_name
).filter(product_id__in=keys)
product_id_variant_channel_listings_map = defaultdict(list)
- for product_channel_listing in product_channel_listings.iterator():
+ for product_channel_listing in product_channel_listings.iterator(
+ chunk_size=1000
+ ):
product_id_variant_channel_listings_map[
product_channel_listing.product_id
].append(product_channel_listing)
@@ -132,7 +134,9 @@ class ProductChannelListingByProductIdAndChannelSlugLoader(
).filter(channel__slug=channel_slug, product_id__in=products_ids)
product_channel_listings_map: dict[int, ProductChannelListing] = {}
- for product_channel_listing in product_channel_listings.iterator():
+ for product_channel_listing in product_channel_listings.iterator(
+ chunk_size=1000
+ ):
product_channel_listings_map[product_channel_listing.product_id] = (
product_channel_listing
)
@@ -161,7 +165,7 @@ class MediaByProductIdLoader(DataLoader[int, list[ProductMedia]]):
product_id__in=keys,
)
media_map = defaultdict(list)
- for media_obj in media.iterator():
+ for media_obj in media.iterator(chunk_size=1000):
media_map[media_obj.product_id].append(media_obj)
return [media_map[product_id] for product_id in keys]
@@ -175,7 +179,7 @@ class ImagesByProductIdLoader(DataLoader[int, list[ProductMedia]]):
type=ProductMediaTypes.IMAGE,
)
images_map = defaultdict(list)
- for image in images.iterator():
+ for image in images.iterator(chunk_size=1000):
images_map[image.product_id].append(image)
return [images_map[product_id] for product_id in keys]
@@ -199,7 +203,7 @@ class ProductVariantsByProductIdLoader(DataLoader[int, list[ProductVariant]]):
)
variant_map = defaultdict(list)
variant_loader = ProductVariantByIdLoader(self.context)
- for variant in variants.iterator():
+ for variant in variants.iterator(chunk_size=1000):
variant_map[variant.product_id].append(variant)
variant_loader.prime(variant.id, variant)
return [variant_map.get(product_id, []) for product_id in keys]
@@ -233,7 +237,7 @@ class ProductVariantsByProductIdAndChannel(
.order_by("sort_order", "sku")
)
- for variant in variants.iterator():
+ for variant in variants.iterator(chunk_size=1000):
key = (variant.product_id, channel.slug)
variant_map[key].append(variant)
@@ -286,7 +290,9 @@ class VariantChannelListingByVariantIdLoader(DataLoader):
)
variant_id_variant_channel_listings_map = defaultdict(list)
- for variant_channel_listing in variant_channel_listings.iterator():
+ for variant_channel_listing in variant_channel_listings.iterator(
+ chunk_size=1000
+ ):
variant_id_variant_channel_listings_map[
variant_channel_listing.variant_id
].append(variant_channel_listing)
@@ -366,7 +372,9 @@ class VariantChannelListingByVariantIdAndChannelIdLoader(
)
variant_channel_listings_map: dict[int, ProductVariantChannelListing] = {}
- for variant_channel_listing in variant_channel_listings.iterator():
+ for variant_channel_listing in variant_channel_listings.iterator(
+ chunk_size=1000
+ ):
variant_channel_listings_map[variant_channel_listing.variant_id] = (
variant_channel_listing
)
@@ -427,7 +435,9 @@ class VariantsChannelListingByProductIdAndChannelSlugLoader(
variants_channel_listings_map: dict[int, list[ProductVariantChannelListing]] = (
defaultdict(list)
)
- for variant_channel_listing in variants_channel_listings.iterator():
+ for variant_channel_listing in variants_channel_listings.iterator(
+ chunk_size=1000
+ ):
variants_channel_listings_map[
getattr(variant_channel_listing, "product_id") # annotation
].append(variant_channel_listing)
@@ -472,7 +482,7 @@ class MediaByProductVariantIdLoader(DataLoader):
variant_media_pairs = defaultdict(list)
media_ids = set()
- for variant_id, media_id in variant_media.iterator():
+ for variant_id, media_id in variant_media.iterator(chunk_size=1000):
variant_media_pairs[variant_id].append(media_id)
media_ids.add(media_id)
@@ -504,7 +514,7 @@ class ImagesByProductVariantIdLoader(DataLoader):
)
variant_media_pairs = defaultdict(list)
- for variant_id, media_id in variant_media.iterator():
+ for variant_id, media_id in variant_media.iterator(chunk_size=1000):
variant_media_pairs[variant_id].append(media_id)
def map_variant_media(variant_media):
@@ -540,7 +550,7 @@ class CollectionsByProductIdLoader(DataLoader):
.filter(product_id__in=keys)
.order_by("id")
.values_list("product_id", "collection_id")
- .iterator()
+ .iterator(chunk_size=1000)
)
product_collection_map = defaultdict(list)
for pid, cid in product_collection_pairs:
@@ -622,7 +632,9 @@ class CollectionChannelListingByCollectionIdLoader(DataLoader):
self.database_connection_name
).filter(collection_id__in=keys)
collection_id_collection_channel_listings_map = defaultdict(list)
- for collection_channel_listing in collections_channel_listings.iterator():
+ for collection_channel_listing in collections_channel_listings.iterator(
+ chunk_size=1000
+ ):
collection_id_collection_channel_listings_map[
collection_channel_listing.collection_id
].append(collection_channel_listing)
@@ -645,7 +657,9 @@ class CollectionChannelListingByCollectionIdAndChannelSlugLoader(DataLoader):
.order_by("pk")
)
collections_channel_listings_by_collection_and_channel_map = {}
- for collections_channel_listing in collections_channel_listings.iterator():
+ for collections_channel_listing in collections_channel_listings.iterator(
+ chunk_size=1000
+ ):
key = (
collections_channel_listing.collection_id,
collections_channel_listing.channel_slug,
@@ -667,7 +681,7 @@ class CategoryChildrenByCategoryIdLoader(DataLoader):
parent_id__in=keys
)
parent_to_children_mapping = defaultdict(list)
- for category in categories.iterator():
+ for category in categories.iterator(chunk_size=1000):
parent_to_children_mapping[category.parent_id].append(category)
return [parent_to_children_mapping.get(key, []) for key in keys]
diff --git a/saleor/graphql/product/types/channels.py b/saleor/graphql/product/types/channels.py
index 3f27fd4709..668a5c67e4 100644
--- a/saleor/graphql/product/types/channels.py
+++ b/saleor/graphql/product/types/channels.py
@@ -279,7 +279,7 @@ class ProductChannelListing(ModelObjectType[models.ProductChannelListing]):
tax_class_id
)
if tax_class_id
- else []
+ else Promise.resolve([])
)
default_country_rate = TaxClassDefaultRateByCountryLoader(
context
diff --git a/saleor/graphql/product/types/products.py b/saleor/graphql/product/types/products.py
index 64386bd999..ecc2ff245c 100644
--- a/saleor/graphql/product/types/products.py
+++ b/saleor/graphql/product/types/products.py
@@ -687,7 +687,7 @@ class ProductVariant(ChannelContextType[models.ProductVariant]):
tax_class_id
)
if tax_class_id
- else []
+ else Promise.resolve([])
)
default_rate = TaxClassDefaultRateByCountryLoader(context).load(
country_code
@@ -1200,7 +1200,7 @@ class Product(ChannelContextType[models.Product]):
tax_class_id
)
if tax_class_id
- else []
+ else Promise.resolve([])
)
default_rate = TaxClassDefaultRateByCountryLoader(context).load(
country_code
diff --git a/saleor/graphql/shop/utils.py b/saleor/graphql/shop/utils.py
index 53ff5299bd..4f07bc89ef 100644
--- a/saleor/graphql/shop/utils.py
+++ b/saleor/graphql/shop/utils.py
@@ -19,7 +19,9 @@ def get_countries_codes_list(
all_countries_codes = {country[0] for country in countries}
if attached_to_shipping_zones is not None:
covered_countries_codes = set()
- for zone in ShippingZone.objects.using(database_connection_name).iterator():
+ for zone in ShippingZone.objects.using(database_connection_name).iterator(
+ chunk_size=1000
+ ):
covered_countries_codes.update({country.code for country in zone.countries})
if attached_to_shipping_zones:
diff --git a/saleor/graphql/utils/__init__.py b/saleor/graphql/utils/__init__.py
index 007b621a0d..a0086ed0f7 100644
--- a/saleor/graphql/utils/__init__.py
+++ b/saleor/graphql/utils/__init__.py
@@ -61,7 +61,7 @@ def resolve_global_ids_to_primary_keys(
ids: Iterable[str], graphene_type=None, raise_error: bool = False
):
pks = []
- invalid_ids = []
+ invalid_ids: list[str] = []
used_type = graphene_type
for graphql_id in ids:
diff --git a/saleor/invoice/migrations/0010_alter_invoice_metadata_and_more.py b/saleor/invoice/migrations/0010_alter_invoice_metadata_and_more.py
new file mode 100644
index 0000000000..edceff128c
--- /dev/null
+++ b/saleor/invoice/migrations/0010_alter_invoice_metadata_and_more.py
@@ -0,0 +1,34 @@
+# Generated by Django 5.2 on 2025-04-18 10:39
+
+from django.db import migrations, models
+
+import saleor.core.utils.json_serializer
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("invoice", "0009_alter_invoice_options"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="invoice",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="invoice",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ ]
diff --git a/saleor/menu/migrations/0023_alter_menu_metadata_alter_menu_private_metadata_and_more.py b/saleor/menu/migrations/0023_alter_menu_metadata_alter_menu_private_metadata_and_more.py
new file mode 100644
index 0000000000..0a99250c8a
--- /dev/null
+++ b/saleor/menu/migrations/0023_alter_menu_metadata_alter_menu_private_metadata_and_more.py
@@ -0,0 +1,54 @@
+# Generated by Django 5.2 on 2025-04-18 10:39
+
+from django.db import migrations, models
+
+import saleor.core.utils.json_serializer
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("menu", "0022_alter_menuitemtranslation_language_code"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="menu",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="menu",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="menuitem",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="menuitem",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ ]
diff --git a/saleor/order/migrations/0201_alter_fulfillment_metadata_and_more.py b/saleor/order/migrations/0201_alter_fulfillment_metadata_and_more.py
new file mode 100644
index 0000000000..cf5b8fed1d
--- /dev/null
+++ b/saleor/order/migrations/0201_alter_fulfillment_metadata_and_more.py
@@ -0,0 +1,114 @@
+# Generated by Django 5.2 on 2025-04-18 10:39
+
+from django.db import migrations, models
+
+import saleor.core.utils.json_serializer
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("order", "0200_order_with_waiting_for_approval_fulfillments"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="fulfillment",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="fulfillment",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="order",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="order",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="order",
+ name="shipping_tax_class_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="order",
+ name="shipping_tax_class_private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="orderline",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="orderline",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="orderline",
+ name="tax_class_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="orderline",
+ name="tax_class_private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ ]
diff --git a/saleor/order/migrations/0203_merge_20250527_1210.py b/saleor/order/migrations/0203_merge_20250527_1210.py
new file mode 100644
index 0000000000..add9e8d374
--- /dev/null
+++ b/saleor/order/migrations/0203_merge_20250527_1210.py
@@ -0,0 +1,12 @@
+# Generated by Django 5.2 on 2025-05-27 12:10
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("order", "0201_alter_fulfillment_metadata_and_more"),
+ ("order", "0202_alter_order_undiscounted_base_shipping_price_amount"),
+ ]
+
+ operations = []
diff --git a/saleor/order/models.py b/saleor/order/models.py
index 50287b9748..f596efa1c9 100644
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -250,10 +250,10 @@ class Order(ModelWithMetadata, ModelWithExternalReference):
)
shipping_tax_class_name = models.CharField(max_length=255, blank=True, null=True)
shipping_tax_class_private_metadata = JSONField(
- blank=True, null=True, default=dict, encoder=CustomJsonEncoder
+ blank=True, db_default={}, default=dict, encoder=CustomJsonEncoder
)
shipping_tax_class_metadata = JSONField(
- blank=True, null=True, default=dict, encoder=CustomJsonEncoder
+ blank=True, db_default={}, default=dict, encoder=CustomJsonEncoder
)
# Token of a checkout instance that this order was created from
@@ -708,10 +708,10 @@ class OrderLine(ModelWithMetadata):
)
tax_class_name = models.CharField(max_length=255, blank=True, null=True)
tax_class_private_metadata = JSONField(
- blank=True, null=True, default=dict, encoder=CustomJsonEncoder
+ blank=True, db_default={}, default=dict, encoder=CustomJsonEncoder
)
tax_class_metadata = JSONField(
- blank=True, null=True, default=dict, encoder=CustomJsonEncoder
+ blank=True, db_default={}, default=dict, encoder=CustomJsonEncoder
)
is_price_overridden = models.BooleanField(null=True, blank=True)
diff --git a/saleor/page/migrations/0031_alter_page_metadata_alter_page_private_metadata_and_more.py b/saleor/page/migrations/0031_alter_page_metadata_alter_page_private_metadata_and_more.py
new file mode 100644
index 0000000000..6843518f9d
--- /dev/null
+++ b/saleor/page/migrations/0031_alter_page_metadata_alter_page_private_metadata_and_more.py
@@ -0,0 +1,54 @@
+# Generated by Django 5.2 on 2025-04-18 10:39
+
+from django.db import migrations, models
+
+import saleor.core.utils.json_serializer
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("page", "0030_slug_translation_unique_constraint"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="page",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="page",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="pagetype",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="pagetype",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ ]
diff --git a/saleor/page/models.py b/saleor/page/models.py
index 761b094263..3dd3dfbee3 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,misc]
+ objects = PageManager() # type: ignore[misc]
class Meta(ModelWithMetadata.Meta):
ordering = ("slug",)
diff --git a/saleor/payment/dataloaders.py b/saleor/payment/dataloaders.py
index 446ded528a..bce7115ae4 100644
--- a/saleor/payment/dataloaders.py
+++ b/saleor/payment/dataloaders.py
@@ -14,6 +14,6 @@ class PaymentsByOrderIdLoader(DataLoader):
.order_by("pk")
)
payment_map = defaultdict(list)
- for payment in payments.iterator():
+ for payment in payments.iterator(chunk_size=1000):
payment_map[payment.order_id].append(payment)
return [payment_map.get(order_id, []) for order_id in keys]
diff --git a/saleor/payment/gateways/np_atobarai/plugin.py b/saleor/payment/gateways/np_atobarai/plugin.py
index 41a4c11375..4c69619ef9 100644
--- a/saleor/payment/gateways/np_atobarai/plugin.py
+++ b/saleor/payment/gateways/np_atobarai/plugin.py
@@ -156,9 +156,8 @@ class NPAtobaraiGatewayPlugin(BasePlugin):
@classmethod
def validate_authentication(cls, plugin_configuration: "PluginConfiguration"):
- conf = {
- data["name"]: data["value"] for data in plugin_configuration.configuration
- }
+ configuration = plugin_configuration.configuration
+ conf = {data["name"]: data["value"] for data in configuration}
with np_atobarai_otel_trace("np-atobarai.utilities.ping"):
response = health_check(get_api_config(conf))
diff --git a/saleor/payment/gateways/stripe/plugin.py b/saleor/payment/gateways/stripe/plugin.py
index d8ede7e08e..8bb226ff0c 100644
--- a/saleor/payment/gateways/stripe/plugin.py
+++ b/saleor/payment/gateways/stripe/plugin.py
@@ -536,7 +536,7 @@ class StripeGatewayPlugin(BasePlugin):
if not webhook_id and not webhook_secret_data.get("value"):
webhook = subscribe_webhook(
api_key,
- plugin_configuration.channel.slug, # type: ignore[arg-type,union-attr]
+ plugin_configuration.channel.slug, # type: ignore[union-attr]
)
if not webhook:
@@ -552,7 +552,9 @@ class StripeGatewayPlugin(BasePlugin):
)
@classmethod
- def _update_or_create_config_field(cls, configuration, field, value):
+ def _update_or_create_config_field(
+ cls, configuration: list[dict], field: str, value
+ ):
for c_field in configuration:
if c_field["name"] == field:
c_field["value"] = value
diff --git a/saleor/payment/migrations/0060_alter_payment_metadata_and_more.py b/saleor/payment/migrations/0060_alter_payment_metadata_and_more.py
new file mode 100644
index 0000000000..263cbf67f4
--- /dev/null
+++ b/saleor/payment/migrations/0060_alter_payment_metadata_and_more.py
@@ -0,0 +1,54 @@
+# Generated by Django 5.2 on 2025-04-18 10:39
+
+from django.db import migrations, models
+
+import saleor.core.utils.json_serializer
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("payment", "0059_merge_20240802_1125"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="payment",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="payment",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="transactionitem",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="transactionitem",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ ]
diff --git a/saleor/payment/migrations/0061_merge_20250527_1210.py b/saleor/payment/migrations/0061_merge_20250527_1210.py
new file mode 100644
index 0000000000..d9ac1c10a9
--- /dev/null
+++ b/saleor/payment/migrations/0061_merge_20250527_1210.py
@@ -0,0 +1,12 @@
+# Generated by Django 5.2 on 2025-05-27 12:10
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("payment", "0060_alter_payment_captured_amount_alter_payment_total_and_more"),
+ ("payment", "0060_alter_payment_metadata_and_more"),
+ ]
+
+ operations = []
diff --git a/saleor/plugins/avatax/__init__.py b/saleor/plugins/avatax/__init__.py
index ab39a307e3..42a4ea7aba 100644
--- a/saleor/plugins/avatax/__init__.py
+++ b/saleor/plugins/avatax/__init__.py
@@ -403,7 +403,7 @@ def get_order_lines_data(
undiscounted_amount = prices_data.undiscounted_price.net.amount
price_with_discounts_amount = prices_data.price_with_discounts.net.amount
- append_line_to_data_kwargs = {
+ append_line_to_data_kwargs: dict[str, Any] = {
"data": data,
"quantity": line.quantity,
# This is a workaround for Avatax and sending a lines with amount 0. Like
diff --git a/saleor/plugins/base_plugin.py b/saleor/plugins/base_plugin.py
index 8408d9c3a2..fee2a84a94 100644
--- a/saleor/plugins/base_plugin.py
+++ b/saleor/plugins/base_plugin.py
@@ -1812,7 +1812,7 @@ class BasePlugin:
def save_plugin_configuration(
cls, plugin_configuration: "PluginConfiguration", cleaned_data
):
- current_config = plugin_configuration.configuration
+ current_config: list[dict] = plugin_configuration.configuration
configuration_to_update = cleaned_data.get("configuration")
if configuration_to_update:
cls._update_config_items(configuration_to_update, current_config)
diff --git a/saleor/plugins/manager.py b/saleor/plugins/manager.py
index 1e07229af5..c5e1157f4d 100644
--- a/saleor/plugins/manager.py
+++ b/saleor/plugins/manager.py
@@ -205,7 +205,7 @@ class PluginsManager(PaymentInterface):
self.database
).filter(channel=channel)
configs = {}
- for db_plugin_config in plugin_manager_configs.iterator():
+ for db_plugin_config in plugin_manager_configs.iterator(chunk_size=1000):
configs[db_plugin_config.identifier] = db_plugin_config
return configs
@@ -2508,7 +2508,7 @@ class PluginsManager(PaymentInterface):
def get_all_plugins(self, active_only=False):
if not self.loaded_all_channels:
channels = Channel.objects.using(self.database).all()
- for channel in channels.iterator():
+ for channel in channels.iterator(chunk_size=1000):
self._ensure_channel_plugins_loaded(channel.slug, channel=channel)
self.loaded_all_channels = True
return self.get_plugins(active_only=active_only)
diff --git a/saleor/plugins/migrations/0011_alter_pluginconfiguration_configuration.py b/saleor/plugins/migrations/0011_alter_pluginconfiguration_configuration.py
new file mode 100644
index 0000000000..1fd0a0b707
--- /dev/null
+++ b/saleor/plugins/migrations/0011_alter_pluginconfiguration_configuration.py
@@ -0,0 +1,23 @@
+# Generated by Django 5.2 on 2025-04-18 10:39
+
+from django.db import migrations, models
+
+import saleor.core.utils.json_serializer
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("plugins", "0010_auto_20220104_1239"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="pluginconfiguration",
+ name="configuration",
+ field=models.JSONField(
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ ]
diff --git a/saleor/plugins/models.py b/saleor/plugins/models.py
index 7c9bcba39b..49448b2707 100644
--- a/saleor/plugins/models.py
+++ b/saleor/plugins/models.py
@@ -14,9 +14,7 @@ class PluginConfiguration(models.Model):
)
description = models.TextField(blank=True)
active = models.BooleanField(default=False)
- configuration = JSONField(
- blank=True, null=True, default=dict, encoder=CustomJsonEncoder
- )
+ configuration = JSONField(db_default={}, default=dict, encoder=CustomJsonEncoder)
class Meta:
unique_together = ("identifier", "channel")
diff --git a/saleor/product/migrations/0198_alter_collection_products.py b/saleor/product/migrations/0198_alter_collection_products.py
new file mode 100644
index 0000000000..ecab7f368e
--- /dev/null
+++ b/saleor/product/migrations/0198_alter_collection_products.py
@@ -0,0 +1,23 @@
+# Generated by Django 5.2 on 2025-04-17 13:52
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("product", "0197_productvariantchannellisting_prior_price_amount"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="collection",
+ name="products",
+ field=models.ManyToManyField(
+ blank=True,
+ related_name="collections",
+ through="product.CollectionProduct",
+ through_fields=("collection", "product"),
+ to="product.product",
+ ),
+ ),
+ ]
diff --git a/saleor/product/migrations/0199_alter_category_metadata_and_more.py b/saleor/product/migrations/0199_alter_category_metadata_and_more.py
new file mode 100644
index 0000000000..900b650ada
--- /dev/null
+++ b/saleor/product/migrations/0199_alter_category_metadata_and_more.py
@@ -0,0 +1,154 @@
+# Generated by Django 5.2 on 2025-04-18 10:39
+
+from django.db import migrations, models
+
+import saleor.core.utils.json_serializer
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("product", "0198_alter_collection_products"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="category",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="category",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="collection",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="collection",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="digitalcontent",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="digitalcontent",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="product",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="product",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="productmedia",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="productmedia",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="producttype",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="producttype",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="productvariant",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="productvariant",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ ]
diff --git a/saleor/product/migrations/0200_merge_20250527_1210.py b/saleor/product/migrations/0200_merge_20250527_1210.py
new file mode 100644
index 0000000000..5fe93e1d6e
--- /dev/null
+++ b/saleor/product/migrations/0200_merge_20250527_1210.py
@@ -0,0 +1,12 @@
+# Generated by Django 5.2 on 2025-05-27 12:10
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("product", "0199_alter_category_metadata_and_more"),
+ ("product", "0199_alter_productvariantchannellisting_prior_price_amount"),
+ ]
+
+ operations = []
diff --git a/saleor/product/search.py b/saleor/product/search.py
index edf3862c46..f0c50fb28d 100644
--- a/saleor/product/search.py
+++ b/saleor/product/search.py
@@ -129,8 +129,7 @@ def generate_attributes_search_vector_value(
product_attributes = product.product_type.attributeproduct.all()
attributes = [
- product_attribute.attribute # type: ignore[attr-defined]
- for product_attribute in product_attributes
+ product_attribute.attribute for product_attribute in product_attributes
][: settings.PRODUCT_MAX_INDEXED_ATTRIBUTES]
assigned_values = product.attributevalues.all()
diff --git a/saleor/product/tasks.py b/saleor/product/tasks.py
index 018647ecb7..3e56e691d0 100644
--- a/saleor/product/tasks.py
+++ b/saleor/product/tasks.py
@@ -132,7 +132,7 @@ def _get_channel_to_products_map(rule_to_variant_list):
)
rule_to_channels_map = defaultdict(set)
- for promotionrule_id, channel_id in promotion_channel_qs.iterator():
+ for promotionrule_id, channel_id in promotion_channel_qs.iterator(chunk_size=1000):
rule_to_channels_map[promotionrule_id].add(channel_id)
channel_to_products_map = defaultdict(set)
for rule_to_variant in rule_to_variant_list:
diff --git a/saleor/product/utils/product.py b/saleor/product/utils/product.py
index 624b37b443..1359514449 100644
--- a/saleor/product/utils/product.py
+++ b/saleor/product/utils/product.py
@@ -116,7 +116,9 @@ def mark_products_in_channels_as_dirty(
product_id__in=product_ids, channel_id__in=channels
).values_list("id", "product_id", "channel_id")
- for id, product_id, channel_id in product_channel_listings.iterator():
+ for id, product_id, channel_id in product_channel_listings.iterator(
+ chunk_size=1000
+ ):
product_ids = channel_to_product_ids.get(channel_id, set())
if product_id in product_ids:
listing_ids_to_update.append(id)
diff --git a/saleor/product/utils/variant_prices.py b/saleor/product/utils/variant_prices.py
index 39ccbdcfd7..f4cf1e96bd 100644
--- a/saleor/product/utils/variant_prices.py
+++ b/saleor/product/utils/variant_prices.py
@@ -190,12 +190,14 @@ def _get_product_to_variant_channel_listings_per_channel_map(
variant_channel_listings = ProductVariantChannelListing.objects.filter(
Exists(variants.filter(id=OuterRef("variant_id"))), price_amount__isnull=False
)
- variant_to_product_id = dict(variants.values_list("id", "product_id").iterator())
+ variant_to_product_id = dict(
+ variants.values_list("id", "product_id").iterator(chunk_size=1000)
+ )
price_data: dict[int, dict[int, list[Money]]] = defaultdict(
lambda: defaultdict(list)
)
- for variant_channel_listing in variant_channel_listings.iterator():
+ for variant_channel_listing in variant_channel_listings.iterator(chunk_size=1000):
try:
product_id = variant_to_product_id[variant_channel_listing.variant_id]
except KeyError:
diff --git a/saleor/product/utils/variants.py b/saleor/product/utils/variants.py
index 23766dc04d..e06efbc5f8 100644
--- a/saleor/product/utils/variants.py
+++ b/saleor/product/utils/variants.py
@@ -24,7 +24,7 @@ def generate_and_set_variant_name(
assignment__attribute__type=AttributeType.PRODUCT_TYPE,
)
attribute_rel: AssignedVariantAttribute
- for attribute_rel in variant_selection_attributes.iterator():
+ for attribute_rel in variant_selection_attributes.iterator(chunk_size=1000):
values_qs = attribute_rel.values.all()
attributes_display.append(", ".join([str(value) for value in values_qs]))
@@ -58,7 +58,7 @@ def fetch_variants_for_promotion_rules(rules: QuerySet[PromotionRule]):
PromotionRuleVariant = PromotionRule.variants.through
new_rules_variants = []
- for rule in rules.iterator():
+ for rule in rules.iterator(chunk_size=1000):
variants = get_variants_for_catalogue_predicate(
rule.catalogue_predicate,
database_connection_name=settings.DATABASE_CONNECTION_REPLICA_NAME,
diff --git a/saleor/schedulers/models.py b/saleor/schedulers/models.py
index d299726e3c..f5e7ddca0e 100644
--- a/saleor/schedulers/models.py
+++ b/saleor/schedulers/models.py
@@ -1,14 +1,17 @@
import importlib
+from typing import TYPE_CHECKING, Union
from celery.schedules import BaseSchedule
from django.core.exceptions import SuspiciousOperation, ValidationError
from django.db import models
from django.db.models import signals
from django_celery_beat import models as base_models
-from django_celery_beat import querysets
from . import customschedule
+if TYPE_CHECKING:
+ from django.db.models.expressions import Combinable
+
class CustomSchedule(models.Model): # type: ignore[django-manager-missing] # problem with django-stubs # noqa: E501
"""Defines the db model storing the details of a custom Celery beat schedulers.
@@ -68,25 +71,34 @@ class CustomSchedule(models.Model): # type: ignore[django-manager-missing] # pr
return f"{self.schedule_import_path=}"
-PeriodicTaskManager = models.Manager.from_queryset(querysets.PeriodicTaskQuerySet)
+class PeriodicTaskQuerySet(models.QuerySet["CustomPeriodicTask"]):
+ def enabled(self):
+ return self.filter(enabled=True).prefetch_related(
+ "interval", "crontab", "solar", "clocked"
+ )
+
+
+PeriodicTaskManager = models.Manager.from_queryset(PeriodicTaskQuerySet)
class CustomPeriodicTask(base_models.PeriodicTask):
no_changes = False
- custom = models.ForeignKey(
- CustomSchedule,
- on_delete=models.CASCADE,
- null=True,
- blank=True,
- verbose_name="Custom Schedule",
- help_text=(
- "Custom Schedule to run the task on. "
- "Set only one schedule type, leave the others null."
- ),
+ custom: models.ForeignKey[Union[CustomSchedule, "Combinable"], CustomSchedule] = (
+ models.ForeignKey(
+ CustomSchedule,
+ on_delete=models.CASCADE,
+ null=True,
+ blank=True,
+ verbose_name="Custom Schedule",
+ help_text=(
+ "Custom Schedule to run the task on. "
+ "Set only one schedule type, leave the others null."
+ ),
+ )
)
- objects = PeriodicTaskManager()
+ objects: PeriodicTaskManager = PeriodicTaskManager()
def validate_unique(self, *args, **kwargs):
models.Model.validate_unique(self, *args, **kwargs)
diff --git a/saleor/settings.py b/saleor/settings.py
index 511b058633..4711cc3906 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -842,7 +842,7 @@ for entry_point in installed_plugins:
INSTALLED_APPS.append(entry_point.name)
EXTERNAL_PLUGINS.append(plugin_path)
-PLUGINS = BUILTIN_PLUGINS + EXTERNAL_PLUGINS
+PLUGINS: list[str] = BUILTIN_PLUGINS + EXTERNAL_PLUGINS
# When `True`, HTTP requests made from arbitrary URLs will be rejected (e.g., webhooks).
# if they try to access private IP address ranges, and loopback ranges (unless
diff --git a/saleor/shipping/migrations/0035_alter_shippingmethod_metadata_and_more.py b/saleor/shipping/migrations/0035_alter_shippingmethod_metadata_and_more.py
new file mode 100644
index 0000000000..a55c75efb7
--- /dev/null
+++ b/saleor/shipping/migrations/0035_alter_shippingmethod_metadata_and_more.py
@@ -0,0 +1,54 @@
+# Generated by Django 5.2 on 2025-04-18 10:39
+
+from django.db import migrations, models
+
+import saleor.core.utils.json_serializer
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("shipping", "0034_shippingzone_countries_idx"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="shippingmethod",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="shippingmethod",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="shippingzone",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="shippingzone",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ ]
diff --git a/saleor/shipping/migrations/0036_merge_20250527_1210.py b/saleor/shipping/migrations/0036_merge_20250527_1210.py
new file mode 100644
index 0000000000..f0bfa759d5
--- /dev/null
+++ b/saleor/shipping/migrations/0036_merge_20250527_1210.py
@@ -0,0 +1,15 @@
+# Generated by Django 5.2 on 2025-05-27 12:10
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("shipping", "0035_alter_shippingmethod_metadata_and_more"),
+ (
+ "shipping",
+ "0035_alter_shippingmethodchannellisting_maximum_order_price_amount_and_more",
+ ),
+ ]
+
+ operations = []
diff --git a/saleor/shipping/models.py b/saleor/shipping/models.py
index c0fd493ecd..9e938d3b23 100644
--- a/saleor/shipping/models.py
+++ b/saleor/shipping/models.py
@@ -187,7 +187,7 @@ class ShippingMethodQueryset(models.QuerySet["ShippingMethod"]):
if lines is None:
# TODO: lines should comes from args in get_valid_shipping_methods_for_order
lines = list(
- instance.lines.prefetch_related("variant__product") # type: ignore[misc] # this is hack # noqa: E501
+ instance.lines.prefetch_related("variant__product")
.using(database_connection_name)
.all()
)
diff --git a/saleor/site/migrations/0041_alter_sitesettings_metadata_and_more.py b/saleor/site/migrations/0041_alter_sitesettings_metadata_and_more.py
new file mode 100644
index 0000000000..1d20c55031
--- /dev/null
+++ b/saleor/site/migrations/0041_alter_sitesettings_metadata_and_more.py
@@ -0,0 +1,34 @@
+# Generated by Django 5.2 on 2025-04-18 10:39
+
+from django.db import migrations, models
+
+import saleor.core.utils.json_serializer
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("site", "0040_sitesettings_allow_login_without_confirmation"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="sitesettings",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="sitesettings",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ ]
diff --git a/saleor/tax/migrations/0009_alter_taxclass_metadata_and_more.py b/saleor/tax/migrations/0009_alter_taxclass_metadata_and_more.py
new file mode 100644
index 0000000000..441c5fd341
--- /dev/null
+++ b/saleor/tax/migrations/0009_alter_taxclass_metadata_and_more.py
@@ -0,0 +1,54 @@
+# Generated by Django 5.2 on 2025-04-18 10:39
+
+from django.db import migrations, models
+
+import saleor.core.utils.json_serializer
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("tax", "0008_auto_20240122_1353"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="taxclass",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="taxclass",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="taxconfiguration",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="taxconfiguration",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ ]
diff --git a/saleor/tax/migrations/0010_merge_20250527_1210.py b/saleor/tax/migrations/0010_merge_20250527_1210.py
new file mode 100644
index 0000000000..110f91630b
--- /dev/null
+++ b/saleor/tax/migrations/0010_merge_20250527_1210.py
@@ -0,0 +1,12 @@
+# Generated by Django 5.2 on 2025-05-27 12:10
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("tax", "0009_alter_taxclass_metadata_and_more"),
+ ("tax", "0009_alter_taxclasscountryrate_rate"),
+ ]
+
+ operations = []
diff --git a/saleor/thumbnail/views.py b/saleor/thumbnail/views.py
index 3697d25490..63b878037b 100644
--- a/saleor/thumbnail/views.py
+++ b/saleor/thumbnail/views.py
@@ -95,11 +95,11 @@ def handle_thumbnail(request, instance_id: str, size: str, format: str | None =
try:
if object_type in UUID_IDENTIFIABLE_TYPES:
- instance = model_data.model.objects.using( # type: ignore[misc]
+ instance = model_data.model.objects.using(
settings.DATABASE_CONNECTION_REPLICA_NAME
- ).get(uuid=pk)
+ ).get(uuid=pk) # type: ignore[misc]
else:
- instance = model_data.model.objects.using( # type: ignore[misc]
+ instance = model_data.model.objects.using(
settings.DATABASE_CONNECTION_REPLICA_NAME
).get(id=pk)
except ObjectDoesNotExist:
diff --git a/saleor/warehouse/management.py b/saleor/warehouse/management.py
index 8b8f9a2fed..34e87cd6b6 100644
--- a/saleor/warehouse/management.py
+++ b/saleor/warehouse/management.py
@@ -971,7 +971,7 @@ def _get_stock_for_preorder_allocation(
if shipping_method_id is not None:
warehouse = Warehouse.objects.filter(
- shipping_zones__id=order.shipping_method.shipping_zone_id # type: ignore[misc,union-attr]
+ shipping_zones__id=order.shipping_method.shipping_zone_id # type: ignore[union-attr]
).first()
else:
from ..order.utils import get_order_country
diff --git a/saleor/warehouse/migrations/0035_alter_warehouse_metadata_and_more.py b/saleor/warehouse/migrations/0035_alter_warehouse_metadata_and_more.py
new file mode 100644
index 0000000000..6d33b5786d
--- /dev/null
+++ b/saleor/warehouse/migrations/0035_alter_warehouse_metadata_and_more.py
@@ -0,0 +1,34 @@
+# Generated by Django 5.2 on 2025-04-18 10:39
+
+from django.db import migrations, models
+
+import saleor.core.utils.json_serializer
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("warehouse", "0034_warehouse_click_and_collect_option_idx"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="warehouse",
+ name="metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="warehouse",
+ name="private_metadata",
+ field=models.JSONField(
+ blank=True,
+ db_default={},
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ ),
+ ),
+ ]
diff --git a/saleor/webhook/observability/utils.py b/saleor/webhook/observability/utils.py
index 49ffd075c7..fda7f6144f 100644
--- a/saleor/webhook/observability/utils.py
+++ b/saleor/webhook/observability/utils.py
@@ -154,7 +154,7 @@ class ApiCall:
@contextmanager
-def report_api_call(request: "HttpRequest") -> Generator[ApiCall, None, None]:
+def report_api_call(request: "HttpRequest") -> Generator[ApiCall]:
root = False
if not hasattr(_context, "api_call"):
_context.api_call, root = ApiCall(request), True
@@ -165,7 +165,7 @@ def report_api_call(request: "HttpRequest") -> Generator[ApiCall, None, None]:
@contextmanager
-def report_gql_operation() -> Generator[GraphQLOperationResponse, None, None]:
+def report_gql_operation() -> Generator[GraphQLOperationResponse]:
root = False
if not hasattr(_context, "gql_operation"):
_context.gql_operation, root = GraphQLOperationResponse(), True
diff --git a/saleor/webhook/serializers.py b/saleor/webhook/serializers.py
index 1955c07ee0..1a063a97b9 100644
--- a/saleor/webhook/serializers.py
+++ b/saleor/webhook/serializers.py
@@ -119,7 +119,7 @@ def serialize_product_attributes(product: "Product") -> list[dict]:
values_map[av.value.attribute_id].append(av.value)
for attribute_product in attribute_products:
- attribute = attribute_product.attribute # type: ignore[attr-defined]
+ attribute = attribute_product.attribute
attr_id = graphene.Node.to_global_id("Attribute", attribute.pk)
attr_data: dict[Any, Any] = {