Adds smart json support for WTForms. Useful for when using WTForms with RESTful APIs.

Does not work with flask-admin due to override of formdata#24

Open
Opened 5/30/20141 commentsby cybertoast
cybertoast

The specific issue is that if wtforms_json is used, the [monkey patch](https://github.com/kvesteri/wtforms-json/blob/master/wtforms_json/__init__.py#L179) does not allow fallthrough/bubble-up of different datatypes. For example, if using flask-admin and a StringField is overridden on the form as a FileUploadField, the formdata processor will normally parse the provided data, save the file, and store the filename to the StringField. The monkey patch breaks this process since it transforms all input types into their text representation via `six`: ``` if isinstance(self, TextField): if self.data is None: self.data = u'' else: self.data = six.text_type(self.data) ``` This is obviously incorrect. I'm not sure about the motivations for this code, so can't say what the correct solution would be. I actually suspect that this block of code should be removed altogether, since it's certainly possible that the back-end should store no value if that's what's received - rather than a blank string. Or it should be handled as the model expects, rather than as overridden text. I'm happy to submit a pull request, but wanted to first understand what the intentions were.

AI Analysis

This issue appears to be discussing a feature request or bug report related to the repository. Based on the content, it seems to be still under discussion. The issue was opened by cybertoast and has received 1 comments.

Add a comment
Comment form would go here