django-cms / django-cms

The easy-to-use and developer-friendly enterprise CMS powered by Django
http://www.django-cms.org
BSD 3-Clause "New" or "Revised" License
10.23k stars 3.12k forks source link

[BUG] Field languages in model Page may be inconsistent #8019

Closed jrief closed 1 day ago

jrief commented 1 month ago

Description

I currently have no receipt to reproduce this, but apparently we have an inconsistency in our database regarding the field languages in model Page.

Steps to reproduce

This currently is not reproducible, but I can explain what is happening using the Django shell:

>>> from cms.models.pagemodel import *
>>> page = Page.objects.get(id=21179)
>>> page.languages
'de'
>>> page.get_content_obj('de').language
'de'
>>> page.get_content_obj('en').language
'en'

Expected behaviour

Since the German and English page content objects are published, I would expect that page.languages == 'de,en'

Actual behaviour

page.languages == 'de'

Additional information (CMS/Python/Django versions)

Django-CMS-4.1.1

Do you want to help fix this issue?

Since this field is non-normalized, at least there should be a management command to fix it in case of data corruption.

fsbraun commented 1 month ago

I fear versioning might interfere with the proper update of the languages field. The information is clearly redundant and was a performance compromise in v3. Have you checked if list(page_obj.page_content_cache.keys()) would work for you? If so, we consider should

As long as you are at least accessing one language, this does not create additional database queries.

fsbraun commented 1 month ago

Something like this for the Page model - the languages field would be removed then:

def get_languages(self):
    self._get_page_content_cache(None, False, False)
    return list(self.page_content_cache.keys())

@property
def languages(self):
   return ",".join(self.get_languages())
jrief commented 1 month ago

if this doesn't hurt performance, it certainly would be a better solution.

What about using @cached_property?