question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error in forms listing in admin

See original GitHub issue

Issue Summary

I have a site which i was working well with wagtail -2.16.x, i’m making a renewal and migration of the whole site, i have a few forms, but when i did try to test it, seems to work twice, but when i look in admin section ‘Forms’ an error appears about ‘str’ object is not a mapping

Steps to Reproduce

  1. Start a new project with wagtail start myproject
  2. Edit models.py to add a AbstractFormField model, and a AbstractEmailForm model:

class FormularioFormField(AbstractFormField): pagina = ParentalKey(“Formulario”, on_delete=models.CASCADE, related_name=“campos_formulario”) …

class Formulario(PaginaBaseAbstract, AbstractEmailForm): …

  1. Create a few pages in admin of type ‘Formulario’
  2. Go to public view fo that form and fill a few forms.
  3. return to wagtail admin, and go to forms
  4. open your forms with data filled
  5. see that error jumps…
  • I have confirmed that this issue can be reproduced as described on a fresh Wagtail project: YES

Technical details

  • Python version: 3.10
  • Django version: 4.0.1
  • Wagtail version: 3.0
  • Browser version: Firefox 99

btw, i found the solution, in the file wagtail/contrib/forms/models.py

line 57 (into get_data func):

**self.form_data,

def get_data(self):
     """
     Returns dict with form data.
     You can override this method to add additional data.
     """
     return {
         **self.form_data,
         "submit_time": self.submit_time,
     }

checking the same file in 2.16 y change a bit to make it similar, so i change it to:

def get_data(self):
     form_data = json.loads(self.form_data)
     form_data.update({'submit_time': self.submit_time})
     return form_data

obviously must import json first

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
gasmancommented, Jun 7, 2022

For reference, the same thing has been reported on the Wagtail Slack support channel but is unresolved there - if this does turn out to be a missed step in the upgrade process then we should highlight this in the release notes.

0reactions
tbrlpldcommented, Oct 19, 2022

I just ran into this issue too. It looks like I had a bad record in the database. I guess that record was created after the migration ran to convert the table to JSON but before I had updated the process_form_submission to not use json.dumps anymore.

Here you can see the bad record in the database with id 4.

picnic=# select * from myforms_myformsubmission;
 id |              form_data               |          submit_time          | page_id | user_id 
----+--------------------------------------+-------------------------------+---------+---------
  1 | {"what_is_your_name": "Alice"}       | 2022-10-11 14:11:16.587711+00 |       5 |       1
  2 | {"what_is_your_name": "Bob"}         | 2022-10-11 14:11:23.633996+00 |       5 |       1
  3 | {"what_is_your_name": "Alice again"} | 2022-10-17 15:30:33.813545+00 |       5 |        
  4 | "{\"what_is_your_name\": \"Test\"}"  | 2022-10-19 13:47:23.80316+00  |       5 |        
  5 | {"what_is_your_name": "Test"}        | 2022-10-19 13:48:12.425547+00 |       5 |        
(5 rows)

picnic=# delete from myforms_myformsubmission where id=4;
DELETE 1
picnic=# select * from myforms_myformsubmission;
 id |              form_data               |          submit_time          | page_id | user_id 
----+--------------------------------------+-------------------------------+---------+---------
  1 | {"what_is_your_name": "Alice"}       | 2022-10-11 14:11:16.587711+00 |       5 |       1
  2 | {"what_is_your_name": "Bob"}         | 2022-10-11 14:11:23.633996+00 |       5 |       1
  3 | {"what_is_your_name": "Alice again"} | 2022-10-17 15:30:33.813545+00 |       5 |        
  5 | {"what_is_your_name": "Test"}        | 2022-10-19 13:48:12.425547+00 |       5 |        

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error in form - WordPress.org
I have 2 forms using Fluent Forms on my page, 1 has no problem, but the other has a console error even though...
Read more >
errors in fields not displaying on Django admin form
I have checked all the fields in the model, and all the required fields have been filled out. Nevertheless, I continue to get...
Read more >
Admin information - Microsoft Forms Admin
This article answers the most Frequently Asked Questions about admin information for Microsoft Forms.
Read more >
Submitting form via admin-post.php and handling errors
I'm submitting this form using admin-post.php . Inside functions.php I have my function to process the form, which is working. I can display...
Read more >
Errors in fields not displaying on Django admin form - Edureka
at the top of the form, yet no fields are highlighted with an error message. What can be another cause, and how do...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found