Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BooleanField not populated by obj if empty formdata given #686

Closed
sergehauri opened this issue Apr 8, 2021 · 1 comment
Closed

BooleanField not populated by obj if empty formdata given #686

sergehauri opened this issue Apr 8, 2021 · 1 comment

Comments

@sergehauri
Copy link

The documentation on Form states:

obj – If formdata is empty or not provided, this object is checked for attributes matching form field names, which will be used for field values

However, with BooleanFields this isn't true: If formdata is empty, a BooleanField's data will be set to False, no matter what the value of obj is.

Actual Behavior

>>> import wtforms
>>> class F(wtforms.Form):
...     foo = wtforms.BooleanField()
... 
>>> class DummyObj:
...     def __init__(self):
...         self.foo = True
... 
>>> class DummyPostData(dict):
...     def getlist(self, key):
...         v = self[key]
...         if not isinstance(v, (list, tuple)):
...             v = [v]
...         return v
... 
>>> f = F(formdata=DummyPostData(), obj=DummyObj())
>>> f.foo.data
False
>>> f.foo.object_data
True

Expected Behavior

>>> f = F(formdata=DummyPostData(), obj=DummyObj())
>>> f.foo.data
True
>>> f.foo.object_data
True

Environment

  • Python version: 3.8.0
  • wtforms version: 2.3.3
@davidism
Copy link
Member

davidism commented Apr 8, 2021

Duplicate of #662, #402, or one of these.

@davidism davidism closed this as completed Apr 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants