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:
Create
TestPagewith at least oneTestChildinline model.Publish
TestPage.Edit the created
TestPageagain, delete theTestChild, and add a new one.Publish
TestPageand save changes.Go to the history of the edited TestPage and review the previous revision.
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.