Skip to content

Commit 7ed3301

Browse files
committed
⬆️(back) upgrade django to version 5.2
Django 5.2 is now mature enough and we can use it in production. In some tests the number of sql queries is increasing. This is because the `full_clean` method called in the `save` method on all our models is creating a transaction, so a savepoint and release is added. We also fix deprecated warning in this commit.
1 parent a99c813 commit 7ed3301

File tree

8 files changed

+18
-19
lines changed

8 files changed

+18
-19
lines changed

renovate.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@
99
"matchManagers": ["pep621"],
1010
"matchPackageNames": []
1111
},
12-
{
13-
"groupName": "allowed django versions",
14-
"matchManagers": ["pep621"],
15-
"matchPackageNames": ["Django"],
16-
"allowedVersions": "<5.2"
17-
},
1812
{
1913
"groupName": "allowed redis versions",
2014
"matchManagers": ["pep621"],

src/backend/core/factories.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class UserFactory(factory.django.DjangoModelFactory):
3535

3636
class Meta:
3737
model = models.User
38+
# Skip postgeneration save, no save is made in the postgeneration methods.
39+
skip_postgeneration_save = True
3840

3941
sub = factory.Sequence(lambda n: f"user{n!s}")
4042
email = factory.Faker("email")

src/backend/core/migrations/0001_initial.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ class Migration(migrations.Migration):
504504
migrations.AddConstraint(
505505
model_name="documentaccess",
506506
constraint=models.CheckConstraint(
507-
check=models.Q(
507+
condition=models.Q(
508508
models.Q(("team", ""), ("user__isnull", False)),
509509
models.Q(("team__gt", ""), ("user__isnull", True)),
510510
_connector="OR",
@@ -540,7 +540,7 @@ class Migration(migrations.Migration):
540540
migrations.AddConstraint(
541541
model_name="templateaccess",
542542
constraint=models.CheckConstraint(
543-
check=models.Q(
543+
condition=models.Q(
544544
models.Q(("team", ""), ("user__isnull", False)),
545545
models.Q(("team__gt", ""), ("user__isnull", True)),
546546
_connector="OR",

src/backend/core/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ class Meta:
520520
verbose_name_plural = _("Documents")
521521
constraints = [
522522
models.CheckConstraint(
523-
check=(
523+
condition=(
524524
models.Q(deleted_at__isnull=True)
525525
| models.Q(deleted_at=models.F("ancestors_deleted_at"))
526526
),
@@ -1088,7 +1088,7 @@ class Meta:
10881088
violation_error_message=_("This team is already in this document."),
10891089
),
10901090
models.CheckConstraint(
1091-
check=models.Q(user__isnull=False, team="")
1091+
condition=models.Q(user__isnull=False, team="")
10921092
| models.Q(user__isnull=True, team__gt=""),
10931093
name="check_document_access_either_user_or_team",
10941094
violation_error_message=_("Either user or team must be set, not both."),
@@ -1236,7 +1236,7 @@ class Meta:
12361236
violation_error_message=_("This team is already in this template."),
12371237
),
12381238
models.CheckConstraint(
1239-
check=models.Q(user__isnull=False, team="")
1239+
condition=models.Q(user__isnull=False, team="")
12401240
| models.Q(user__isnull=True, team__gt=""),
12411241
name="check_template_access_either_user_or_team",
12421242
violation_error_message=_("Either user or team must be set, not both."),

src/backend/core/tests/documents/test_api_documents_update_extract_attachments.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def test_api_documents_update_new_attachment_keys_anonymous(django_assert_num_qu
4747
factories.DocumentFactory(attachments=[image_keys[3]], link_reach="restricted")
4848
expected_keys = {image_keys[i] for i in [0, 1]}
4949

50-
with django_assert_num_queries(9):
50+
with django_assert_num_queries(11):
5151
response = APIClient().put(
5252
f"/api/v1.0/documents/{document.id!s}/",
5353
{"content": get_ydoc_with_mages(image_keys)},
@@ -60,7 +60,7 @@ def test_api_documents_update_new_attachment_keys_anonymous(django_assert_num_qu
6060

6161
# Check that the db query to check attachments readability for extracted
6262
# keys is not done if the content changes but no new keys are found
63-
with django_assert_num_queries(5):
63+
with django_assert_num_queries(7):
6464
response = APIClient().put(
6565
f"/api/v1.0/documents/{document.id!s}/",
6666
{"content": get_ydoc_with_mages(image_keys[:2])},
@@ -98,7 +98,7 @@ def test_api_documents_update_new_attachment_keys_authenticated(
9898
factories.DocumentFactory(attachments=[image_keys[4]], users=[user])
9999
expected_keys = {image_keys[i] for i in [0, 1, 2, 4]}
100100

101-
with django_assert_num_queries(10):
101+
with django_assert_num_queries(12):
102102
response = client.put(
103103
f"/api/v1.0/documents/{document.id!s}/",
104104
{"content": get_ydoc_with_mages(image_keys)},
@@ -111,7 +111,7 @@ def test_api_documents_update_new_attachment_keys_authenticated(
111111

112112
# Check that the db query to check attachments readability for extracted
113113
# keys is not done if the content changes but no new keys are found
114-
with django_assert_num_queries(6):
114+
with django_assert_num_queries(8):
115115
response = client.put(
116116
f"/api/v1.0/documents/{document.id!s}/",
117117
{"content": get_ydoc_with_mages(image_keys[:2])},

src/backend/core/tests/test_models_documents.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,7 @@ def test_models_documents_restore(django_assert_num_queries):
10641064
assert document.deleted_at is not None
10651065
assert document.ancestors_deleted_at == document.deleted_at
10661066

1067-
with django_assert_num_queries(8):
1067+
with django_assert_num_queries(10):
10681068
document.restore()
10691069
document.refresh_from_db()
10701070
assert document.deleted_at is None
@@ -1107,7 +1107,7 @@ def test_models_documents_restore_complex(django_assert_num_queries):
11071107
assert child2.ancestors_deleted_at == document.deleted_at
11081108

11091109
# Restore the item
1110-
with django_assert_num_queries(11):
1110+
with django_assert_num_queries(13):
11111111
document.restore()
11121112
document.refresh_from_db()
11131113
child1.refresh_from_db()
@@ -1157,7 +1157,7 @@ def test_models_documents_restore_complex_bis(django_assert_num_queries):
11571157

11581158
# Restoring the grand parent should not restore the document
11591159
# as it was deleted before the grand parent
1160-
with django_assert_num_queries(9):
1160+
with django_assert_num_queries(11):
11611161
grand_parent.restore()
11621162

11631163
grand_parent.refresh_from_db()

src/backend/impress/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,9 @@ class Test(Base):
849849
"django.contrib.auth.hashers.MD5PasswordHasher",
850850
]
851851
USE_SWAGGER = True
852+
# Static files are not used in the test environment
853+
# Tests are raising warnings because the /data/static directory does not exist
854+
STATIC_ROOT = None
852855

853856
CELERY_TASK_ALWAYS_EAGER = values.BooleanValue(True)
854857

src/backend/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ dependencies = [
3838
"django-redis==5.4.0",
3939
"django-storages[s3]==1.14.6",
4040
"django-timezone-field>=5.1",
41-
"django==5.1.10",
41+
"django==5.2.3",
4242
"django-treebeard==4.7.1",
4343
"djangorestframework==3.16.0",
4444
"drf_spectacular==0.28.0",

0 commit comments

Comments
 (0)