From 0745ae53da1ee206dab22884d9ec94bb46eaf9ca Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Sat, 1 Mar 2025 00:01:45 +0000 Subject: [PATCH] Test that validation is still enforced on save_revision when saving or scheduling As per https://github.com/wagtail/rfcs/pull/104#issuecomment-2691145020 - unless clean=False is explicitly passed, validation should be applied, including on fields that would accept nulls at the database level. --- wagtail/tests/test_page_model.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/wagtail/tests/test_page_model.py b/wagtail/tests/test_page_model.py index 53ab4fd15a..7fd86b742c 100644 --- a/wagtail/tests/test_page_model.py +++ b/wagtail/tests/test_page_model.py @@ -982,6 +982,20 @@ class TestSaveRevision(TestCase): "page.save_revision() must be called on the specific version of the page. Call page.specific.save_revision() instead.", ) + def test_validate_on_save_revision(self): + christmas_event = EventPage.objects.get(url_path="/home/events/christmas/") + christmas_event.date_from = None + with self.assertRaises(ValidationError): + christmas_event.save_revision() + + def test_validate_on_schedule_revision(self): + christmas_event = EventPage.objects.get(url_path="/home/events/christmas/") + christmas_event.date_from = None + with self.assertRaises(ValidationError): + christmas_event.save_revision( + approved_go_live_at=timezone.now() + datetime.timedelta(days=1) + ) + class TestLiveRevision(TestCase): fixtures = ["test.json"]