Skip to content

⬆️(back) upgrade django to version 5.2 #1079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 17, 2025
Merged

⬆️(back) upgrade django to version 5.2 #1079

merged 2 commits into from
Jun 17, 2025

Conversation

lunika
Copy link
Member

@lunika lunika commented Jun 16, 2025

Purpose

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.

Proposal

  • ⬆️(back) upgrade django to version 5.2

@lunika lunika requested review from qbey and Copilot June 16, 2025 13:18
@lunika lunika self-assigned this Jun 16, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR upgrades Django to version 5.2.3 and addresses resulting deprecations and test adjustments.

  • Bumps Django from 5.1.10 to 5.2.3 and updates SQL query counts in tests to match the new full_clean transaction behavior.
  • Replaces deprecated check argument with condition in CheckConstraint declarations and migrations.
  • Adds STATIC_ROOT = None in test settings, introduces skip_postgeneration_save in the user factory, and cleans up the Renovate configuration.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/backend/pyproject.toml Updated Django version to 5.2.3
src/backend/impress/settings.py Added STATIC_ROOT = None override
src/backend/core/tests/test_models_documents.py Increased expected SQL query counts in document restore tests
src/backend/core/tests/documents/test_api_documents_update_extract_attachments.py Increased expected SQL query counts in API document update tests
src/backend/core/models.py Switched CheckConstraint(check=…) to condition=…
src/backend/core/migrations/0001_initial.py Updated migration constraints to use condition parameter
src/backend/core/factories.py Added skip_postgeneration_save=True with brief comment
renovate.json Removed obsolete Django version restriction group
Comments suppressed due to low confidence (1)

src/backend/core/factories.py:38

  • [nitpick] This comment is a bit terse. Consider referencing the factory_boy docs or expanding on why skipping postgeneration saves is needed to clarify its impact on related fields.
# Skip postgeneration save, no save is made in the postgeneration methods.

@@ -849,6 +849,7 @@ class Test(Base):
"django.contrib.auth.hashers.MD5PasswordHasher",
]
USE_SWAGGER = True
STATIC_ROOT = None
Copy link
Preview

Copilot AI Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Setting STATIC_ROOT to None may disable static file collection or serving in tests. Consider adding a comment explaining this override or using a temp directory to prevent unexpected behavior when static files are accessed.

Suggested change
STATIC_ROOT = None
# Use a temporary directory for STATIC_ROOT to ensure static files are collected and served during tests.
import tempfile
STATIC_ROOT = tempfile.mkdtemp()

Copilot uses AI. Check for mistakes.

@@ -1064,7 +1064,7 @@ def test_models_documents_restore(django_assert_num_queries):
assert document.deleted_at is not None
assert document.ancestors_deleted_at == document.deleted_at

with django_assert_num_queries(8):
with django_assert_num_queries(10):
Copy link
Preview

Copilot AI Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Hardcoding exact SQL query counts makes tests fragile across future upgrades. Consider asserting a range or delta of queries instead to reduce maintenance when internal Django behavior changes.

Suggested change
with django_assert_num_queries(10):
with django_assert_num_queries(range(8, 12)):

Copilot uses AI. Check for mistakes.

@@ -849,6 +849,7 @@ class Test(Base):
"django.contrib.auth.hashers.MD5PasswordHasher",
]
USE_SWAGGER = True
STATIC_ROOT = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have warning in the tests saying that the /data/static directory does not exists. We can create it or set to None the STATIC_ROOT variable as static are not used in the tests.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

core/tests/test_api_config.py::test_api_config_with_invalid_json_theme_customization_file[False]
core/tests/test_api_config.py::test_api_config_with_invalid_json_theme_customization_file[True]
core/tests/test_api_config.py::test_api_config_with_theme_customization[False]
core/tests/test_api_config.py::test_api_config_with_theme_customization[True]
  /home/runner/.local/lib/python3.13/site-packages/django/core/handlers/base.py:61: UserWarning: No directory at: /data/static/
    mw_instance = middleware(adapted_handler)

@lunika lunika enabled auto-merge (squash) June 16, 2025 14:42
@lunika lunika disabled auto-merge June 17, 2025 10:19
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.
@lunika lunika requested a review from AntoLC June 17, 2025 10:20
Copy link
Collaborator

@AntoLC AntoLC left a comment

The domain extension (.e2e) used in the demo for users are not validated
anymore by the django EmailValidator. We have to change it to a valid
one.
@lunika lunika merged commit 05db9c8 into main Jun 17, 2025
18 of 21 checks passed
@lunika lunika deleted the django-52 branch June 17, 2025 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants