Skip to content

Commit

Permalink
fix: Port forward #7664 and #7657 (#7695)
Browse files Browse the repository at this point in the history
* fix: preserve `view_class` in decorated views (#7664)

* Fix tests

* Bugfix: avoid InvalidCacheKey (memcached) for key-length ~249 (fixes #7595) (#7657)

* Remove docs test from test suite (since covered by separate github action)

* Remove docs requirements from the django-main test

* Add setuptools to requirements for python 3.12

* Add setuptools to requirements.txt

* Fix: Test with current ckeditor

* Undo unnecessary change

* Fix tests for Django 5.1

* Fix: Missing output_field

---------

Co-authored-by: Will Hoey <48737592+Will-Hoey@users.noreply.github.com>
Co-authored-by: wfehr <24782511+wfehr@users.noreply.github.com>
  • Loading branch information
3 people committed Nov 20, 2023
1 parent 5b592b9 commit 20fac70
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 117 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ jobs:
pip install pytest
pip install -r test_requirements/${{ matrix.requirements-file }}
pip install -r test_requirements/databases.txt
pip install -r docs/requirements.txt
python setup.py install
- name: Test with django test runner
Expand Down Expand Up @@ -116,7 +115,6 @@ jobs:
pip install pytest
pip install -r test_requirements/${{ matrix.requirements-file }}
pip install -r test_requirements/databases.txt
pip install -r docs/requirements.txt
python setup.py install
Expand Down Expand Up @@ -161,7 +159,6 @@ jobs:
python -m pip install --upgrade pip
pip install pytest
pip install -r test_requirements/${{ matrix.requirements-file }}
pip install -r docs/requirements.txt
python setup.py install
- name: Test with django test runner
Expand Down Expand Up @@ -196,7 +193,6 @@ jobs:
python -m pip install --upgrade pip
pip install -r test_requirements/${{ matrix.requirements-file }}
pip install pytest ${{ matrix.django-version }}
pip install --upgrade setuptools
python setup.py install
- name: Test with django test runner
Expand Down Expand Up @@ -246,7 +242,6 @@ jobs:
pip install -r test_requirements/${{ matrix.requirements-file }}
pip install pytest ${{ matrix.django-version }}
pip install -r test_requirements/databases.txt
pip install -r docs/requirements.txt
python setup.py install
- name: Test with django test runner
Expand Down Expand Up @@ -297,7 +292,6 @@ jobs:
pip install -r test_requirements/${{ matrix.requirements-file }}
pip install pytest ${{ matrix.django-version }}
pip install -r test_requirements/databases.txt
pip install -r docs/requirements.txt
python setup.py install
- name: Test with django test runner
Expand Down
8 changes: 7 additions & 1 deletion cms/cache/placeholder.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ def _get_placeholder_cache_version_key(placeholder, lang, site_id):
lang=str(lang),
site=site_id,
)
if len(key) > 250:
# django itself adds "version" add the end of cache-keys, e.g. "<key>:1".
# -> If `cache.set()` is for example called with `version=""`, it still adds
# `:` at the end. So if we check the length for `> 250`, a length of 249
# or even 250 ends up in an InvalidCacheKey-exception.
# In order to avoid these errors, we hash the keys at a lower length to also
# have a little buffer.
if len(key) > 200:
key = '{prefix}|{hash}'.format(
prefix=prefix,
hash=hashlib.sha1(key.encode('utf-8')).hexdigest(),
Expand Down
7 changes: 6 additions & 1 deletion cms/models/pagemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,12 @@ def set_as_homepage(self, user=None):

def _get_path_sql_value(self, base_path=''):
if base_path:
new_path = Concat(models.Value(base_path), models.Value('/'), models.F('slug'))
new_path = Concat(
models.Value(base_path),
models.Value('/'),
models.F('slug'),
output_field=models.CharField(),
)
elif base_path is None:
new_path = None
else:
Expand Down
5 changes: 4 additions & 1 deletion cms/test_utils/testcases.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
)
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
Expand Down Expand Up @@ -664,4 +665,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)
99 changes: 0 additions & 99 deletions cms/tests/test_docs.py

This file was deleted.

6 changes: 3 additions & 3 deletions cms/tests/test_placeholder.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ def test_sets_source_when_title_is_created(self):

# check for en
page_content_en = self.get_page_title_obj(page)
self.assertQuerysetEqual(
self.assertQuerySetEqual(
Placeholder.objects.get_for_obj(page_content_en),
page_content_en.get_placeholders(),
transform=lambda x: x,
Expand All @@ -889,7 +889,7 @@ def test_sets_source_when_title_is_created(self):

# check for another language = de
page_content_de = create_page_content('de', 'test page de', page)
self.assertQuerysetEqual(
self.assertQuerySetEqual(
Placeholder.objects.get_for_obj(page_content_de),
page_content_de.get_placeholders(),
transform=lambda x: x,
Expand Down Expand Up @@ -983,7 +983,7 @@ def test_placeholder_relation_field(self):
with self.login_user_context(self.get_superuser()):
self.client.get(get_object_edit_url(poll))

self.assertQuerysetEqual(
self.assertQuerySetEqual(
poll.placeholders.all(),
Placeholder.objects.get_for_obj(poll),
transform=lambda x: x,
Expand Down
2 changes: 1 addition & 1 deletion cms/tests/test_rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def test_passed_plugin_context_processor(instance, placeholder, context):
instance._inst = instance

context = PluginContext(
{'original_context_var': 'original_context_var_ok'},
{'original_context_var': 'original_context_var_ok', "request": None},
instance,
self.test_placeholders['main'], processors=(test_passed_plugin_context_processor,)
)
Expand Down
1 change: 1 addition & 0 deletions cms/utils/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
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')
2 changes: 2 additions & 0 deletions cms/utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def inner(request, *args, **kwargs):
return func(request, *args, **kwargs)
inner.__module__ = func.__module__
inner.__doc__ = func.__doc__
if hasattr(func, "view_class"):
inner.view_class = func.view_class
if hasattr(func, '__name__'):
inner.__name__ = func.__name__
elif hasattr(func, '__class__'):
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'django-sekizai>=0.7',
'djangocms-admin-style>=1.2',
'packaging',
'setuptools',
]


Expand Down
10 changes: 5 additions & 5 deletions test_requirements/requirements_base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ django-formtools
django-sekizai>=0.7
django-treebeard>=4.3
djangocms-admin-style>=1.5
docutils<0.18 # Fix for: https://github.yuuza.net/sphinx-doc/sphinx/issues/9727
djangocms-text-ckeditor
iptools
mock>=2.0.0
Pillow
pyenchant==3.0.1
pyenchant
pyflakes>=2.1
python-coveralls>2.5.0
unittest-xml-reporting==1.11.0
ruff==0.1.0
unittest-xml-reporting
ruff
setuptools # Since python 3.12

# FIXME: - Remove when a django 3.0 compatible djangocms-text-ckeditor version is released
https://github.com/Aiky30/djangocms-text-ckeditor/archive/feature/cms-40-django-30-support-.zip
https://github.com/ojii/django-better-test/archive/8aa2407d097fe3789b74682f0e6bd7d15d449416.zip#egg=django-better-test
https://github.com/ojii/django-app-manage/archive/65da18ef234a4e985710c2c0ec760023695b40fe.zip#egg=django-app-manage

0 comments on commit 20fac70

Please sign in to comment.