From 2d80014bee76c9b23df14800367c75983f6ad491 Mon Sep 17 00:00:00 2001 From: Irtaza Akram Date: Thu, 12 Jun 2025 12:12:54 +0500 Subject: [PATCH] fix: add django 5.2 support --- .github/workflows/ci.yml | 2 +- notesapi/v1/tests/helpers.py | 4 ++-- notesapi/v1/tests/test_views.py | 6 +++--- notesapi/v1/views/common.py | 1 - notesapi/v1/views/elasticsearch.py | 7 +++---- notesserver/settings/common.py | 5 ----- requirements/base.in | 19 +++++++++---------- requirements/base.txt | 10 ++++------ requirements/django.txt | 2 +- requirements/pip.in | 1 - requirements/quality.in | 2 +- requirements/quality.txt | 18 +++++++----------- requirements/test.in | 6 +++--- requirements/test.txt | 14 ++++++-------- tox.ini | 3 ++- 15 files changed, 42 insertions(+), 58 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 83213b47..beeffcc7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: fail-fast: false matrix: python-version: ["3.11", "3.12"] - toxenv: ["django42", "quality", "pii_check", "check_keywords"] + toxenv: ["django42", "django52", "quality", "pii_check", "check_keywords"] services: mysql: diff --git a/notesapi/v1/tests/helpers.py b/notesapi/v1/tests/helpers.py index 84ac49d7..0a7fd809 100644 --- a/notesapi/v1/tests/helpers.py +++ b/notesapi/v1/tests/helpers.py @@ -1,12 +1,12 @@ from calendar import timegm -from datetime import datetime, timedelta +from datetime import UTC, datetime, timedelta import jwt from django.conf import settings def get_id_token(user): - now = datetime.utcnow() + now = datetime.now(UTC) return jwt.encode({ 'aud': settings.CLIENT_ID, 'sub': user, diff --git a/notesapi/v1/tests/test_views.py b/notesapi/v1/tests/test_views.py index 750a61b9..8f7734dc 100644 --- a/notesapi/v1/tests/test_views.py +++ b/notesapi/v1/tests/test_views.py @@ -1,6 +1,6 @@ import unittest from calendar import timegm -from datetime import datetime, timedelta +from datetime import UTC, datetime, timedelta from unittest.mock import patch from urllib import parse @@ -1193,8 +1193,8 @@ class TokenTests(BaseAnnotationViewTests): token_data = { 'aud': settings.CLIENT_ID, 'sub': TEST_USER, - 'iat': timegm(datetime.utcnow().utctimetuple()), - 'exp': timegm((datetime.utcnow() + timedelta(seconds=300)).utctimetuple()), + 'iat': timegm(datetime.now(UTC).utctimetuple()), + 'exp': timegm((datetime.now(UTC) + timedelta(seconds=300)).utctimetuple()), } def _assert_403(self, token): diff --git a/notesapi/v1/views/common.py b/notesapi/v1/views/common.py index 944c82d5..e02ff047 100644 --- a/notesapi/v1/views/common.py +++ b/notesapi/v1/views/common.py @@ -1,4 +1,3 @@ -# pylint:disable=possibly-used-before-assignment import json import logging diff --git a/notesapi/v1/views/elasticsearch.py b/notesapi/v1/views/elasticsearch.py index 32c7207c..354683f7 100644 --- a/notesapi/v1/views/elasticsearch.py +++ b/notesapi/v1/views/elasticsearch.py @@ -66,12 +66,11 @@ class AnnotationSearchView(BaseAnnotationSearchView): def __init__(self, *args, **kwargs): self.client = connections.get_connection( NoteDocument._get_using() - ) # pylint: disable=protected-access - self.index = NoteDocument._index._name # pylint: disable=protected-access + ) + self.index = NoteDocument._index._name self.mapping = ( NoteDocument._doc_type.mapping.properties.name - ) # pylint: disable=protected-access - # pylint: disable=protected-access + ) self.search = Search( using=self.client, index=self.index, doc_type=NoteDocument._doc_type.name ) diff --git a/notesserver/settings/common.py b/notesserver/settings/common.py index 933f31cb..1efe9d72 100644 --- a/notesserver/settings/common.py +++ b/notesserver/settings/common.py @@ -158,8 +158,3 @@ } CSRF_TRUSTED_ORIGINS = [] - -# Django 4.0+ uses zoneinfo if this is not set. We can remove this and -# migrate to zoneinfo after Django 4.2 upgrade. See more on following url -# https://docs.djangoproject.com/en/4.2/releases/4.0/#zoneinfo-default-timezone-implementation -USE_DEPRECATED_PYTZ = True diff --git a/requirements/base.in b/requirements/base.in index 8be8c0bc..1a0076d8 100644 --- a/requirements/base.in +++ b/requirements/base.in @@ -2,22 +2,21 @@ -c constraints.txt Django -requests +django-cors-headers +django-elasticsearch-dsl +django-elasticsearch-dsl-drf djangorestframework drf-spectacular +edx-django-release-util +edx-django-utils +edx-drf-extensions elasticsearch elasticsearch-dsl -django-elasticsearch-dsl -django-elasticsearch-dsl-drf -django-cors-headers +gunicorn # MIT meilisearch mysqlclient -PyJWT -gunicorn # MIT path.py +PyJWT python-dateutil -edx-django-release-util -edx-django-utils -edx-drf-extensions -pytz +requests setuptools diff --git a/requirements/base.txt b/requirements/base.txt index 9f020f7f..fced3260 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -28,9 +28,9 @@ charset-normalizer==3.4.2 # via requests click==8.2.1 # via edx-django-utils -cryptography==45.0.3 +cryptography==45.0.4 # via pyjwt -django==4.2.22 +django==4.2.23 # via # -c https://raw.githubusercontent.com/openedx/edx-lint/master/edx_lint/files/common_constraints.txt # -r requirements/base.in @@ -131,7 +131,7 @@ pyjwt[crypto]==2.10.1 # -r requirements/base.in # drf-jwt # edx-drf-extensions -pymongo==4.13.0 +pymongo==4.13.1 # via edx-opaque-keys pynacl==1.5.0 # via edx-django-utils @@ -139,8 +139,6 @@ python-dateutil==2.9.0.post0 # via # -r requirements/base.in # elasticsearch-dsl -pytz==2025.2 - # via -r requirements/base.in pyyaml==6.0.2 # via # drf-spectacular @@ -149,7 +147,7 @@ referencing==0.36.2 # via # jsonschema # jsonschema-specifications -requests==2.32.3 +requests==2.32.4 # via # -r requirements/base.in # edx-drf-extensions diff --git a/requirements/django.txt b/requirements/django.txt index f1573676..c4d956ec 100644 --- a/requirements/django.txt +++ b/requirements/django.txt @@ -1 +1 @@ -django==4.2.22 +django==4.2.23 diff --git a/requirements/pip.in b/requirements/pip.in index 715478cd..b419ce6d 100644 --- a/requirements/pip.in +++ b/requirements/pip.in @@ -4,4 +4,3 @@ pip setuptools wheel - diff --git a/requirements/quality.in b/requirements/quality.in index e6451e75..55e5185a 100644 --- a/requirements/quality.in +++ b/requirements/quality.in @@ -4,6 +4,6 @@ -r test.txt code-annotations +edx_lint pycodestyle pylint -edx_lint diff --git a/requirements/quality.txt b/requirements/quality.txt index 3158a8db..c5dbd2f8 100644 --- a/requirements/quality.txt +++ b/requirements/quality.txt @@ -76,11 +76,11 @@ colorama==0.4.6 # via # -r requirements/test.txt # tox -coverage[toml]==7.8.2 +coverage[toml]==7.9.0 # via # -r requirements/test.txt # pytest-cov -cryptography==45.0.3 +cryptography==45.0.4 # via # -r requirements/base.txt # -r requirements/test.txt @@ -97,7 +97,7 @@ distlib==0.3.9 # via # -r requirements/test.txt # virtualenv -django==4.2.22 +django==4.2.23 # via # -c https://raw.githubusercontent.com/openedx/edx-lint/master/edx_lint/files/common_constraints.txt # -r requirements/base.txt @@ -198,7 +198,7 @@ elasticsearch-dsl==7.4.1 # django-elasticsearch-dsl-drf factory-boy==3.3.3 # via -r requirements/test.txt -faker==37.3.0 +faker==37.4.0 # via # -r requirements/test.txt # factory-boy @@ -348,7 +348,7 @@ pylint-plugin-utils==0.8.2 # via # pylint-celery # pylint-django -pymongo==4.13.0 +pymongo==4.13.1 # via # -r requirements/base.txt # -r requirements/test.txt @@ -367,7 +367,7 @@ pytest==8.4.0 # -r requirements/test.txt # pytest-cov # pytest-django -pytest-cov==6.1.1 +pytest-cov==6.2.0 # via -r requirements/test.txt pytest-django==4.11.1 # via -r requirements/test.txt @@ -380,10 +380,6 @@ python-slugify==8.0.4 # via # -r requirements/test.txt # code-annotations -pytz==2025.2 - # via - # -r requirements/base.txt - # -r requirements/test.txt pyyaml==6.0.2 # via # -r requirements/base.txt @@ -397,7 +393,7 @@ referencing==0.36.2 # -r requirements/test.txt # jsonschema # jsonschema-specifications -requests==2.32.3 +requests==2.32.4 # via # -r requirements/base.txt # -r requirements/test.txt diff --git a/requirements/test.in b/requirements/test.in index c208272c..790cbb13 100644 --- a/requirements/test.in +++ b/requirements/test.in @@ -5,12 +5,12 @@ astroid code-annotations coverage +ddt +diff-cover +factory_boy more-itertools pep8 pylint -diff-cover -factory_boy -ddt pytest pytest-cov pytest-django diff --git a/requirements/test.txt b/requirements/test.txt index eea1c67a..8df2f366 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -55,11 +55,11 @@ code-annotations==2.3.0 # via -r requirements/test.in colorama==0.4.6 # via tox -coverage[toml]==7.8.2 +coverage[toml]==7.9.0 # via # -r requirements/test.in # pytest-cov -cryptography==45.0.3 +cryptography==45.0.4 # via # -r requirements/base.txt # pyjwt @@ -147,7 +147,7 @@ elasticsearch-dsl==7.4.1 # django-elasticsearch-dsl-drf factory-boy==3.3.3 # via -r requirements/test.in -faker==37.3.0 +faker==37.4.0 # via factory-boy filelock==3.18.0 # via @@ -246,7 +246,7 @@ pyjwt[crypto]==2.10.1 # edx-drf-extensions pylint==3.3.7 # via -r requirements/test.in -pymongo==4.13.0 +pymongo==4.13.1 # via # -r requirements/base.txt # edx-opaque-keys @@ -261,7 +261,7 @@ pytest==8.4.0 # -r requirements/test.in # pytest-cov # pytest-django -pytest-cov==6.1.1 +pytest-cov==6.2.0 # via -r requirements/test.in pytest-django==4.11.1 # via -r requirements/test.in @@ -271,8 +271,6 @@ python-dateutil==2.9.0.post0 # elasticsearch-dsl python-slugify==8.0.4 # via code-annotations -pytz==2025.2 - # via -r requirements/base.txt pyyaml==6.0.2 # via # -r requirements/base.txt @@ -284,7 +282,7 @@ referencing==0.36.2 # -r requirements/base.txt # jsonschema # jsonschema-specifications -requests==2.32.3 +requests==2.32.4 # via # -r requirements/base.txt # edx-drf-extensions diff --git a/tox.ini b/tox.ini index 2c64d0f9..98f5939a 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py{311,312}-django{42}, quality, pii_check, check_keywords +envlist = py{311,312}-django{42,52}, quality, pii_check, check_keywords skipsdist = true isolated_build = true # Enable isolated build environments @@ -7,6 +7,7 @@ isolated_build = true # Enable isolated build environments envdir = {toxworkdir}/{envname} deps = django42: Django>=4.2,<5.0 + django52: Django>=5.2,<6.0 passenv = CONN_MAX_AGE DB_ENGINE