Creating and deleting models can lead to a broken tree in the database
See original GitHub issueIssue Summary
On my development server I see my site has records which don’t match up. It first occured after deleting a number of pages in Wagtail, thus it is likely a bug within Wagtail.
Looking at the table “wagtailcore_page” , the table does NOT match what is shown in wagtail.
In the attachment, notice that “digitale rechten” is a child of “achtergrond & verdieping”, yet numchild indicates 0, where it should be 1. The path does confirm this page is a child of “achtergrond & verdieping” There might be more errors in other tables.
Steps to Reproduce
Leading up to all this, I was working on the models. Initially a model “Article” was allowed as subpage_type of “PublicationIndex” (“achtergrond & verdieping” is a publication index). I modified the models by adding two new page models in between. Now the subpage_type for PublicaitonIndex would allow for a type “Theme”. The subpage_type for “Theme” would allow a type “Subject”, and “Subject” would accept a supage_type “Article”. I then ran makemigrations, followed by migrate, which ran succesfully. Now I wanted to get rid of the leftover Articles which were still a direct child of “PublicationIndex”.
- In the CMS I deleted a bunch of pages, some had children some did not. The goal was to delete all sub-pages of “PublicationIndex”. 2. All subpages seemed to be deleted, I create a new page of type “Theme”. 3. The new page created succesfully, but now the list showed my newly created page AND a page which was meant to be deleted, and did not show up before! 4. I deleted the Article page whihc I had meant to delete. 5. If I try to add another subpage to PublicationIndex, I get
ValidationError at /cms/pages/add/ffs_article/theme/5/{'path': ['Page with this Path already exists.']}
Besides that, the earlier added page “DigitaleRechten” (of type “Theme”) does not show up anywhere in the CMS, while it does show in the database!
- I have confirmed that this issue can be reproduced as described on a fresh Wagtail project: No. But this issue should certainly not occur anyway. A currupted datatable is severe.
Technical details
- Python version: 3.7.0
- Django version: 2.0.8
- Wagtail version: 2.1.2
- Browser version: Firefox/61.0.2
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (5 by maintainers)
Top GitHub Comments
@gasman Thank you for the tip, I will try this!
I just found out that there was a
find_problems
method in mp_tree. The documentation explains that problems can occur when:steplen
value in a model (you must :meth:dump_bulk
first, changesteplen
and then :meth:load_bulk
I keep investigating this problem.
@Paulmolin FYI, running
./manage.py fixtree
should be able to fix errors of this type.