diff --git a/wagtail/wagtailcore/models.py b/wagtail/wagtailcore/models.py index d8b27d271..f0911112d 100644 --- a/wagtail/wagtailcore/models.py +++ b/wagtail/wagtailcore/models.py @@ -587,7 +587,7 @@ class Page(MP_Node, ClusterableModel, Indexed): # Copy child pages if recursive: for child_page in self.get_children(): - child_page.copy(recursive=True, to=page_copy) + child_page.specific.copy(recursive=True, to=page_copy) return page_copy diff --git a/wagtail/wagtailcore/tests/test_page_model.py b/wagtail/wagtailcore/tests/test_page_model.py index fd45ca260..3c67c3c69 100644 --- a/wagtail/wagtailcore/tests/test_page_model.py +++ b/wagtail/wagtailcore/tests/test_page_model.py @@ -274,3 +274,19 @@ class TestCopyPage(TestCase): # Check that the url path was updated self.assertEqual(new_christmas_event.url_path, '/home/new-events-index/christmas/') + + def test_copy_page_copies_recursively_with_child_objects(self): + events_index = EventIndex.objects.get(url_path='/home/events/') + + # Copy it + new_events_index = events_index.copy(recursive=True, title="New events index", slug='new-events-index') + + # Get christmas event + old_christmas_event = events_index.get_children().filter(slug='christmas').first() + new_christmas_event = new_events_index.get_children().filter(slug='christmas').first() + + # Check that the speakers were copied + self.assertEqual(new_christmas_event.specific.speakers.count(), 1, "Child objects weren't copied") + + # Check that the speakers weren't removed from old page + self.assertEqual(old_christmas_event.specific.speakers.count(), 1, "Child objects were removed from the original page")