From d5afeab48e098f28c54450200f2c163a7f8b234a Mon Sep 17 00:00:00 2001 From: Abdulmalik Abdulwahab Date: Thu, 21 Jun 2018 09:48:43 +0100 Subject: [PATCH] return none if page specific_class is not set in PageTypeField to_representation --- wagtail/api/v2/serializers.py | 2 ++ wagtail/api/v2/tests/test_pages.py | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/wagtail/api/v2/serializers.py b/wagtail/api/v2/serializers.py index 08425e61b..e966dd82e 100644 --- a/wagtail/api/v2/serializers.py +++ b/wagtail/api/v2/serializers.py @@ -79,6 +79,8 @@ class PageTypeField(Field): return instance def to_representation(self, page): + if page.specific_class is None: + return None name = page.specific_class._meta.app_label + '.' + page.specific_class.__name__ self.context['view'].seen_types[name] = page.specific_class return name diff --git a/wagtail/api/v2/tests/test_pages.py b/wagtail/api/v2/tests/test_pages.py index dfe56504c..5e13b07db 100644 --- a/wagtail/api/v2/tests/test_pages.py +++ b/wagtail/api/v2/tests/test_pages.py @@ -80,12 +80,12 @@ class TestPageListing(TestCase): response = self.get_response() content = json.loads(response.content.decode('UTF-8')) self.assertEqual(content['meta']['total_count'], new_total_count) - + def test_page_listing_with_missing_page_model(self): # Create a ContentType that doesn't correspond to a real model missing_page_content_type = ContentType.objects.create(app_label='tests', model='missingpage') - - # Turn a BlogEntryPage into this + + # Turn a BlogEntryPage into this content_type models.BlogEntryPage.objects.filter(id=16).update(content_type=missing_page_content_type) # get page listing with missing model @@ -916,12 +916,12 @@ class TestPageDetail(TestCase): self.assertIn('related_links', content) self.assertEqual(content['feed_image'], None) - + def test_page_with_missing_page_model(self): # Create a ContentType that doesn't correspond to a real model missing_page_content_type = ContentType.objects.create(app_label='tests', model='missingpage') - - # Turn a BlogEntryPage into this + + # Turn a BlogEntryPage into this content_type models.BlogEntryPage.objects.filter(id=16).update(content_type=missing_page_content_type) # get missing model page