From 67337ac69e7587771e9e51292eda83159f9a8565 Mon Sep 17 00:00:00 2001 From: Josh Peng Yu Date: Fri, 8 Mar 2024 03:26:18 +0000 Subject: [PATCH] fix: workflow and django 4.2 compatibility issues --- .github/workflows/test.yml | 6 +-- cms/__init__.py | 1 - cms/cms_config.py | 2 +- cms/signals/__init__.py | 42 +++---------------- .../project/app_using_non_feature/__init__.py | 1 - .../project/app_with_bad_cms_file/__init__.py | 1 - .../project/app_with_cms_config/__init__.py | 1 - .../project/app_with_cms_feature/__init__.py | 1 - .../__init__.py | 1 - .../__init__.py | 1 - .../__init__.py | 1 - .../__init__.py | 1 - .../app_without_cms_app_class/__init__.py | 1 - .../project/app_without_cms_file/__init__.py | 1 - cms/test_utils/testcases.py | 7 +++- cms/tests/__init__.py | 7 ++++ cms/utils/compat/__init__.py | 18 +++++--- menus/__init__.py | 1 - 18 files changed, 35 insertions(+), 59 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 69d232b9f63..b459bbea4f5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: [ 3.8, 3.9, 3.10 ] # latest release minus two + python-version: [ 3.8, 3.9, '3.10' ] # latest release minus two requirements-file: [ django-3.2.txt, django-4.2.txt @@ -57,7 +57,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: [ 3.8, 3.9, 3.10 ] # latest release minus two + python-version: [ 3.8, 3.9, '3.10' ] # latest release minus two requirements-file: [ django-3.2.txt, django-4.2.txt, @@ -105,7 +105,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: [ 3.8, 3.9, 3.10 ] # latest release minus two + python-version: [ 3.8, 3.9, '3.10' ] # latest release minus two requirements-file: [ django-3.2.txt, django-4.2.txt, diff --git a/cms/__init__.py b/cms/__init__.py index 7363a1e2fd9..8f2dcac6cfa 100644 --- a/cms/__init__.py +++ b/cms/__init__.py @@ -1,3 +1,2 @@ __version__ = '4.0.1.dev2' -default_app_config = 'cms.apps.CMSConfig' diff --git a/cms/cms_config.py b/cms/cms_config.py index b8fe549bf53..486f22fda8e 100644 --- a/cms/cms_config.py +++ b/cms/cms_config.py @@ -1,5 +1,5 @@ from logging import getLogger -from collections import Iterable +from collections.abc import Iterable from django.core.exceptions import ImproperlyConfigured diff --git a/cms/signals/__init__.py b/cms/signals/__init__.py index ac2aa9c2046..2a81f423e83 100644 --- a/cms/signals/__init__.py +++ b/cms/signals/__init__.py @@ -13,52 +13,22 @@ #################### Our own signals ################### # fired after page location is changed - is moved from one node to other -page_moved = Signal(providing_args=["instance"]) +page_moved = Signal() # fired if a public page with an apphook is added or changed -urls_need_reloading = Signal(providing_args=[]) +urls_need_reloading = Signal() # *disclaimer* # The generic object operation signals are very likely to change # as their usage evolves. # As a result, rely on these at your own risk -pre_obj_operation = Signal( - providing_args=[ - "operation", - "request", - "token", - "obj", - ] -) +pre_obj_operation = Signal() -post_obj_operation = Signal( - providing_args=[ - "operation", - "request", - "token", - "obj", - ] -) +post_obj_operation = Signal() -pre_placeholder_operation = Signal( - providing_args=[ - "operation", - "request", - "language", - "token", - "origin", - ] -) +pre_placeholder_operation = Signal() -post_placeholder_operation = Signal( - providing_args=[ - "operation", - "request", - "language", - "token", - "origin", - ] -) +post_placeholder_operation = Signal() ################### apphook reloading ################### diff --git a/cms/test_utils/project/app_using_non_feature/__init__.py b/cms/test_utils/project/app_using_non_feature/__init__.py index 7262828c538..e69de29bb2d 100644 --- a/cms/test_utils/project/app_using_non_feature/__init__.py +++ b/cms/test_utils/project/app_using_non_feature/__init__.py @@ -1 +0,0 @@ -default_app_config = 'cms.test_utils.project.app_using_non_feature.apps.NonFeatureCMSConfig' diff --git a/cms/test_utils/project/app_with_bad_cms_file/__init__.py b/cms/test_utils/project/app_with_bad_cms_file/__init__.py index f093da3cfa9..e69de29bb2d 100644 --- a/cms/test_utils/project/app_with_bad_cms_file/__init__.py +++ b/cms/test_utils/project/app_with_bad_cms_file/__init__.py @@ -1 +0,0 @@ -default_app_config = 'cms.test_utils.project.app_with_bad_cms_file.apps.BadCMSFileConfig' diff --git a/cms/test_utils/project/app_with_cms_config/__init__.py b/cms/test_utils/project/app_with_cms_config/__init__.py index ce7ec3f01c1..e69de29bb2d 100644 --- a/cms/test_utils/project/app_with_cms_config/__init__.py +++ b/cms/test_utils/project/app_with_cms_config/__init__.py @@ -1 +0,0 @@ -default_app_config = 'cms.test_utils.project.app_with_cms_config.apps.CMSConfigConfig' diff --git a/cms/test_utils/project/app_with_cms_feature/__init__.py b/cms/test_utils/project/app_with_cms_feature/__init__.py index 137461ac6d6..e69de29bb2d 100644 --- a/cms/test_utils/project/app_with_cms_feature/__init__.py +++ b/cms/test_utils/project/app_with_cms_feature/__init__.py @@ -1 +0,0 @@ -default_app_config = 'cms.test_utils.project.app_with_cms_feature.apps.CMSFeatureConfig' diff --git a/cms/test_utils/project/app_with_cms_feature_and_config/__init__.py b/cms/test_utils/project/app_with_cms_feature_and_config/__init__.py index 01465b286f0..e69de29bb2d 100644 --- a/cms/test_utils/project/app_with_cms_feature_and_config/__init__.py +++ b/cms/test_utils/project/app_with_cms_feature_and_config/__init__.py @@ -1 +0,0 @@ -default_app_config = 'cms.test_utils.project.app_with_cms_feature_and_config.apps.CMSFeatureAndConfigConfig' diff --git a/cms/test_utils/project/app_with_feature_not_implemented/__init__.py b/cms/test_utils/project/app_with_feature_not_implemented/__init__.py index 15de5378e13..e69de29bb2d 100644 --- a/cms/test_utils/project/app_with_feature_not_implemented/__init__.py +++ b/cms/test_utils/project/app_with_feature_not_implemented/__init__.py @@ -1 +0,0 @@ -default_app_config = 'cms.test_utils.project.app_with_feature_not_implemented.apps.CMSFeatureConfig' diff --git a/cms/test_utils/project/app_with_two_cms_config_classes/__init__.py b/cms/test_utils/project/app_with_two_cms_config_classes/__init__.py index 548761b502a..e69de29bb2d 100644 --- a/cms/test_utils/project/app_with_two_cms_config_classes/__init__.py +++ b/cms/test_utils/project/app_with_two_cms_config_classes/__init__.py @@ -1 +0,0 @@ -default_app_config = 'cms.test_utils.project.app_with_two_cms_config_classes.apps.TwoCMSAppClassesConfig' diff --git a/cms/test_utils/project/app_with_two_cms_feature_classes/__init__.py b/cms/test_utils/project/app_with_two_cms_feature_classes/__init__.py index a340059416c..e69de29bb2d 100644 --- a/cms/test_utils/project/app_with_two_cms_feature_classes/__init__.py +++ b/cms/test_utils/project/app_with_two_cms_feature_classes/__init__.py @@ -1 +0,0 @@ -default_app_config = 'cms.test_utils.project.app_with_two_cms_feature_classes.apps.TwoCMSAppClassesConfig' diff --git a/cms/test_utils/project/app_without_cms_app_class/__init__.py b/cms/test_utils/project/app_without_cms_app_class/__init__.py index 4109b7b2d8d..e69de29bb2d 100644 --- a/cms/test_utils/project/app_without_cms_app_class/__init__.py +++ b/cms/test_utils/project/app_without_cms_app_class/__init__.py @@ -1 +0,0 @@ -default_app_config = 'cms.test_utils.project.app_without_cms_app_class.apps.WithoutCMSAppClassConfig' diff --git a/cms/test_utils/project/app_without_cms_file/__init__.py b/cms/test_utils/project/app_without_cms_file/__init__.py index 12711318eb7..e69de29bb2d 100644 --- a/cms/test_utils/project/app_without_cms_file/__init__.py +++ b/cms/test_utils/project/app_without_cms_file/__init__.py @@ -1 +0,0 @@ -default_app_config = 'cms.test_utils.project.app_without_cms_file.apps.WithoutCMSFileConfig' diff --git a/cms/test_utils/testcases.py b/cms/test_utils/testcases.py index 9b8ed46b0c5..7d10adcffdd 100644 --- a/cms/test_utils/testcases.py +++ b/cms/test_utils/testcases.py @@ -23,14 +23,15 @@ from cms.api import create_page, add_plugin from cms.middleware.toolbar import ToolbarMiddleware -from cms.plugin_rendering import ContentRenderer, StructureRenderer from cms.models import Page, PageContent from cms.models.permissionmodels import ( GlobalPagePermission, PagePermission, PageUser, ) +from cms.plugin_rendering import ContentRenderer, StructureRenderer from cms.test_utils.util.context_managers import UserLoginContext +from cms.utils.compat import DJANGO_4_1 from cms.utils.conf import get_cms_setting from cms.utils.permissions import set_current_user from cms.utils.urlutils import admin_reverse @@ -663,4 +664,6 @@ class CMSTestCase(BaseCMSTestCase, testcases.TestCase): class TransactionCMSTestCase(CMSTestCase, testcases.TransactionTestCase): - pass + if DJANGO_4_1: + def assertQuerySetEqual(self, *args, **kwargs): + return self.assertQuerysetEqual(*args, **kwargs) diff --git a/cms/tests/__init__.py b/cms/tests/__init__.py index e69de29bb2d..c88fb5d91e7 100644 --- a/cms/tests/__init__.py +++ b/cms/tests/__init__.py @@ -0,0 +1,7 @@ +import django + + +if django.VERSION < (4, 2): # TODO: remove when dropping support for Django < 4.2 + from django.test.testcases import TransactionTestCase + + TransactionTestCase.assertQuerySetEqual = TransactionTestCase.assertQuerysetEqual \ No newline at end of file diff --git a/cms/utils/compat/__init__.py b/cms/utils/compat/__init__.py index 951b8f16ae4..d5bd669f12d 100644 --- a/cms/utils/compat/__init__.py +++ b/cms/utils/compat/__init__.py @@ -1,14 +1,22 @@ from platform import python_version from django import get_version -from distutils.version import LooseVersion + +try: + from packaging.version import Version +except ModuleNotFoundError: + from distutils.version import LooseVersion as Version DJANGO_VERSION = get_version() PYTHON_VERSION = python_version() + # These means "less than or equal to DJANGO_FOO_BAR" -DJANGO_2_2 = LooseVersion(DJANGO_VERSION) < LooseVersion('3.0') -DJANGO_3_0 = LooseVersion(DJANGO_VERSION) < LooseVersion('3.1') -DJANGO_3_1 = LooseVersion(DJANGO_VERSION) < LooseVersion('3.2') -DJANGO_3_2 = LooseVersion(DJANGO_VERSION) < LooseVersion('3.3') +DJANGO_2_2 = Version(DJANGO_VERSION) < Version('3.0') +DJANGO_3_0 = Version(DJANGO_VERSION) < Version('3.1') +DJANGO_3_1 = Version(DJANGO_VERSION) < Version('3.2') +DJANGO_3_2 = Version(DJANGO_VERSION) < Version('3.3') +DJANGO_3 = Version(DJANGO_VERSION) < Version('4.0') +DJANGO_4_1 = Version(DJANGO_VERSION) < Version('4.2') +DJANGO_4_2 = Version(DJANGO_VERSION) < Version('4.3') diff --git a/menus/__init__.py b/menus/__init__.py index 8b2e2941cea..e69de29bb2d 100644 --- a/menus/__init__.py +++ b/menus/__init__.py @@ -1 +0,0 @@ -default_app_config = 'menus.apps.MenusConfig'