You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For a page created manually from Admin, can click into page settings.
For any pages that have been created using the API, getting this error when trying to then click into settings.
MultipleObjectsReturned at /en/admin/cms/pagecontent/158/change/
get() returned more than one PageUrl -- it returned 2!
Looking at the pagecontent table in the dB.
When a page is created manually - one pageholder record is created with template type = INHERIT
When a page, and then pagecontent is created using the API. There are two records -
One which has the template as specified in the pagecontent create call.
The second record has the template specified as template = INHERIT
Essentially looks like the API is firing the creation of the requested record and then an additional default placeholder record is also being created which causes the above settings issue. Also looks like 2x dupe cms_pageurl records are being create as a consequence
Steps to reproduce
Manually create a page from admin screen, click on settings - all ok.
Vs.
Create a page/page content using the API as follows:
Yes extra records in both, a work around to get to the settings after page creation is to delete one instance of the PageURL instance - as this is what is causing the error (and records are 100% identical).
@jamesfogg OK, after looking at your code, I think I know the reason:
create_page already creates a PageContent object
You need to create or get the page. Important: do not forget to provide a created_by argument.
Instead of create_pagecontent you'll have to get the existing content by using page.pagecontent_set(manager="admin_manager").latest_content() Only if this should be empty, create a page content object manually.
From there you get the placeholder.
I expect, if you follow this path, you will only have one page url and only one page content object.
My take-away is that create_pagecontent needs to check if there already is a content object before creating a new one.
For a page created manually from Admin, can click into page settings.
For any pages that have been created using the API, getting this error when trying to then click into settings.
MultipleObjectsReturned at /en/admin/cms/pagecontent/158/change/
get() returned more than one PageUrl -- it returned 2!
Looking at the pagecontent table in the dB.
When a page is created manually - one pageholder record is created with template type = INHERIT
When a page, and then pagecontent is created using the API. There are two records -
One which has the template as specified in the pagecontent create call.
The second record has the template specified as template = INHERIT
Essentially looks like the API is firing the creation of the requested record and then an additional default placeholder record is also being created which causes the above settings issue. Also looks like 2x dupe cms_pageurl records are being create as a consequence
Steps to reproduce
Manually create a page from admin screen, click on settings - all ok.
Vs.
Create a page/page content using the API as follows:
parent_page = self.get_parent_page(parent_path)
node_parent = parent_page.node if parent_page else None
draft_page = Page.objects.filter(pagecontent_set__title=page_title, node__parent=node_parent).first()
Expected behaviour
One cms_pagecontent record to be created when page created via API
Actual behaviour
Two cms_pagecontent records created - one with template specified in the API call, the other with template type = INHERIT
Screenshots
N/A
311 / 4.1
Do you want to help fix this issue?
The text was updated successfully, but these errors were encountered: