diff --git a/wagtail/contrib/forms/models.py b/wagtail/contrib/forms/models.py index f864c5195b..a56deedc53 100644 --- a/wagtail/contrib/forms/models.py +++ b/wagtail/contrib/forms/models.py @@ -59,7 +59,7 @@ class AbstractFormSubmission(models.Model): } def __str__(self): - return self.form_data + return f"{self.form_data}" class Meta: abstract = True diff --git a/wagtail/contrib/forms/tests/test_models.py b/wagtail/contrib/forms/tests/test_models.py index 4b395ab734..11a565522f 100644 --- a/wagtail/contrib/forms/tests/test_models.py +++ b/wagtail/contrib/forms/tests/test_models.py @@ -183,6 +183,26 @@ class TestFormSubmission(TestCase): with self.assertRaises(ValidationError): make_form_page(from_address="not an email") + def test_string_representation_form_submission(self): + """ + Ensure that a form submission can be logged / printed without error. + Broke when converting field to JSON - see #8927 + """ + + self.client.post( + "/contact-us/", + { + "your_email": "bob@example.com", + "your_message": "hello world", + "your_choices": {}, + }, + ) + + self.assertGreaterEqual(FormSubmission.objects.count(), 1) + + submission = FormSubmission.objects.first() + self.assertIn("hello world", str(submission)) + class TestFormWithCustomSubmission(TestCase, WagtailTestUtils): def setUp(self):