Description
Description
Each CMS Page
can have one PageUrl
object per language. If there are more than that, a MultipleObjectsReturned
-exception may be raised.
Steps to reproduce
- Edit the page which is set as Home.
- Save the content.
- Publish that page.
The PageUrl
-object for the home page now has two entries in the database. Reason is this
django-cms/cms/models/pagemodel.py
Lines 292 to 296 in 21d6a6d
code snippet. Here
new_path
is a functional expression containing Concat(ConcatPair(Value('parent_slug'), ConcatPair(Value('/'), F(slug))))
. Since the resulting path
field of the home page must be an empty string the above query can't work.
Alternative reproduction
- Create a page with a named slug and publish as a subpage of another page.
- Create another page with the same slug, but as child of another parent page.
- Move one of those pages so that they become siblings.
Now we get two objects of PageUrl
with the same language
and the same path
entry for different pages. This in my opinion is inconsistent.
I therefore strongly recommend to add unique_together = [['path', 'language'], ['page', 'language']]
to the Meta
-class of the PageUrl
-class.
In my setup I already did this. This is how I found out about the two errors reported before. Otherwise I rarely ran into the problem of hitting a MultipleObjectsReturned
-exception, whose real cause then of course is much harder to detect.
Do you want to help fix this issue?
- Yes, I want to help fix this issue and I will join #workgroup-pr-review on Slack to confirm with the community that a PR is welcome.
- No, I only want to report the issue.
I already patched this locally and would like to know if that proposed model change makes sense.