8000 fix: Language tabs didn't show existing content due to caching issue by filipweidemann · Pull Request #8046 · django-cms/django-cms · GitHub
[go: up one dir, main page]

Skip to content

fix: Language tabs didn't show existing content due to caching issue #8046

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 5 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions cms/admin/pageadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,18 +734,6 @@ def log_change(self, request, object, message):
# Block the admin log for change. A signal takes care of this!
return

def get_object(self, request, object_id, from_field=None):
"""
Return an instance matching the field and value provided, the primary
key is used if no field is provided. Return ``None`` if no match is
found or the object_id fails validation.
"""
obj = super().get_object(request, object_id, from_field)

if obj:
obj.page.admin_content_cache[obj.language] = obj
return obj

def get_admin_url(self, action, *args):
url_name = f"{self.opts.app_label}_{self.opts.model_name}_{action}"
return admin_reverse(url_name, args=args)
Expand Down
13 changes: 10 additions & 3 deletions cms/models/pagemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
logger = getLogger(__name__)


class AdminCacheDict(dict):
"""Dictionary that disallows setting individual items to prevent accidental cache corruption."""
def __setitem__(self, key, value):
raise ValueError("Do not set individual items in the admin cache dict. Use the clear_cache method instead.")


class Page(MP_Node):
"""
A ``Page`` is the basic unit of site structure in django CMS. The CMS uses a hierarchical page model: each page
Expand Down Expand Up @@ -139,7 +145,7 @@ def __init__(self, *args, **kwargs):
self.urls_cache = {}
self.page_content_cache = {}
#: Internal cache for page content objects visible publicly
self.admin_content_cache = {}
self.admin_content_cache = AdminCacheDict()
#: Internal cache for page content objects visible in the admin (i.e. to staff users.)
#: Might be larger than the page_content_cache

Expand Down Expand Up @@ -203,7 +209,7 @@ def get_cached_descendants(self):
def _clear_internal_cache(self):
self.urls_cache = {}
self.page_content_cache = {}
self.admin_content_cache = {}
self.admin_content_cache = AdminCacheDict()

if hasattr(self, '_prefetched_objects_cache'):
del self._prefetched_objects_cache
Expand Down Expand Up @@ -722,7 +728,8 @@ def set_translations_cache(self):
self.page_content_cache.setdefault(translation.language, translation)

def set_admin_content_cache(self):
for translation in self.pagecontent_set(manager="admin_manager").current_content().all():
self.admin_conent_cache = AdminCacheDict()
for translation in self.pagecontent_set(manager="admin_manager").latest_content().all():
self.admin_content_cache.setdefault(translation.language, translation)

def get_admin_content(self, language, fallback=False):
Expand Down
Loading
0