'wtforms' processing of incomplete form data

This WTForms 3.0 FAQ entry states (visit the link for full text) :

A key design decision of WTForms was that form data -always- takes precedence when there’s a form submission. That is, if a field exists on a form, and a form was posted, but that field’s value was missing, it will not revert to a default, but instead store an empty value (and in some cases cause a validation error.)

However my program seems not to confirm that.

import wtforms
from werkzeug.datastructures import MultiDict

class MyForm(wtforms.Form):
    field = wtforms.fields.StringField(default='default')
    other = wtforms.fields.StringField()

form = MyForm()
form.process(formdata=MultiDict({'other': 'user'})) # 'field' missing
print(f"{form.field.data=} {form.other.data=}")

There is a form with two fields, but the data for one field is missing. The other field is just for confirming the data was processed.

The program prints:

form.field.data='default' form.other.data='user'

but I was expecting:

form.field.data='' form.other.data='user'

Am I misunderstanding something?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source