Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog
Development
===========
- (Fill this out as you fix issues and develop you features).
- Added Flask-WTF v0.14 support (#294).

Changes in 0.9.0
================
Expand Down
8 changes: 4 additions & 4 deletions flask_mongoengine/wtf/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
class ModelForm(FlaskForm):
"""A WTForms mongoengine model form"""

def __init__(self, formdata=None, obj=None, **kwargs):
self.instance = (kwargs.pop('instance', None) or obj)
def __init__(self, formdata=None, **kwargs):
self.instance = (kwargs.pop('instance', None) or kwargs.get('obj'))
Copy link
Contributor Author

@jcass77 jcass77 Feb 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...thinking about this some more, this should probably be kwargs.get('obj', None) to avoid a KeyError being raised seeing as this is an optional parameter.

Do I need to submit a new PR or will somebody with commit access just make the change?

Copy link
Member

@lafrech lafrech Feb 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm... dict.get defaults to None, right?

assert {'a':1, 'b':2}.get('d') is None

(This is inconsistent with getattr and I was already struck by it once recently.)

Thanks anyway for taking the time to review your own code again. I appreciate.

And considering the little time we dedicate to the maintenance of flask-mongoengine, a PR is appreciated, even for a trivial change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, without checking, I assumed that the code would produce the same result as {'a':1, 'b':2}['d'] - my bad.

if self.instance and not formdata:
obj = self.instance
kwargs['obj'] = self.instance
self.formdata = formdata
super(ModelForm, self).__init__(formdata, obj, **kwargs)
super(ModelForm, self).__init__(formdata, **kwargs)

def save(self, commit=True, **kwargs):
if self.instance:
Expand Down