Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Creating and deleting models can lead to a broken tree in the database

See original GitHub issue

Issue 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. wagtail bug numchild incorrect

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”.

  1. 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:closed
  • Created 5 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

Paulmolincommented, Oct 5, 2018

@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:

  1. your code breaks and you get incomplete transactions (always use transactions!)
  2. changing the steplen value in a model (you must :meth:dump_bulk first, change steplen and then :meth:load_bulk

I keep investigating this problem.

gasmancommented, Oct 5, 2018

@Paulmolin FYI, running ./ fixtreeshould be able to fix errors of this type.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Violation of constraints in relational database - GeeksforGeeks
Deletion operation: On deleting the tuples in the relation, it may cause only violation of Referential integrity constraints. Referential ...
Read more >
Rebuilding the Model from the Database in Visual Studio
It will open a file tree of all the tables contained in your model. Delete every instance of the table you changed in...
Read more >
How should deletions be handled in the database?
What I would like to see is a change at the database architecture level and the application level: create a schema called 'deleted'....
Read more >
All About B Trees and Database - ITNEXT
When deleting, the target node and the deletion index are located. After removing, a node can get out of balance by having too...
Read more >
Phil Waclawski: Using hierarchical data in mysql trees vs nests
Representing that data in a Relational Database starts to get ... If you have access to a mysql instance, you can create the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found