0

I can't revert to previous PageRevisions of TestPage because of hidden ValidationErrors for attached inline TestChild instances. Instead of a useful error message, I get a generic message:

The page could not be saved due to validation errors

Using a debugger allowed me to get more specific error messages for the "id" field of TestChild:

Select a valid choice. That choice is not one of the available choices.

When inspecting the generated Form for TestChild, there is a forms.ModelChoiceField for the "id" pk field, which causes the ValidationError.

The source code below is not the actual code I am using in my project, but it's enough to reproduce the issue.

class TestPage(Page):
    content_panels = Page.content_panels + [InlinePanel("test_children")]
    parent_page_types = ["wagtailcore.Page"]


class TestChild(models.Model):
    parent = ParentalKey(
        TestPage,
        on_delete=models.CASCADE,
        related_name="test_children"
    )
    name = models.CharField(max_length=255)

I am using

  • python 3.12

  • wagtail==7.0.2

  • Django==5.2.4

  • django-modelcluster==6.4

  • wagtail-localize==1.12.2

How to reproduce:

  1. Create TestPage with at least one TestChild inline model.

  2. Publish TestPage.

  3. Edit the created TestPage again, delete the TestChild, and add a new one.

  4. Publish TestPage and save changes.

  5. Go to the history of the edited TestPage and review the previous revision.

  6. Click on "Replace current draft".

Expected Outcome: I can revert to the selected previous PageRevision with all data and inline models restored.

Actual Outcome: Restoring PageRevision fails with generic error message "The page could not be saved due to validation errors"

I hope someone can help me with this issue.

New contributor
Dennis Pratter is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.