You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The specific issue is that if wtforms_json is used, the monkey patch 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.
The text was updated successfully, but these errors were encountered:
StringField from WTForms on this line mangles None to a string not WTForms-JSON. For the same reason that you say, I use a custom StringField class that accepts None:
class StringField(Field):
widget = widgets.TextInput()
def process_formdata(self, valuelist):
if valuelist:
self.data = valuelist[0]
else:
self.data = None
def _value(self):
"""Provides value displayed in HTML form.
"""
return text_type(self.data) if self.data is not None else ''
The specific issue is that if wtforms_json is used, the monkey patch 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
: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.
The text was updated successfully, but these errors were encountered: