Comments (12)
Seems like this is due to the StringField implementation in wtforms which EmailField is based.
https://bitbucket.org/simplecodes/wtforms/src/a5f9e30260cc/wtforms/fields/core.py#cl-466
Wouldn't the same check need to be made in your application whether email was ''
or None
=> if user.email
vs if user.email == None
?
from flask-mongoengine.
@anemitz I'm not entirely sure what you're referencing to now. The problem is, that the way the mongorest emailfield is implemented is, that it will raise a validation error if it's passed in an empty string.
I don't have an issue with it passing back '' however mongonengine does. The testcase doesn't show the entire problem. The whole point of model_form(SomeDocument) is that I can then do something like: SomeDocument(form.data) and if the form validated, the document should also validate. Which it does not, because email='' is invalid.
from flask-mongoengine.
@anemitz I comitted a fix: e55bf96
from flask-mongoengine.
This is correct behavior. email
is supposed to be an empty string instead of None
. Otherwise things will break, e.g. Optional
validation will no longer work properly.
from flask-mongoengine.
@thomasst merged the pull request. Though the same issue might come up for other field types.
from flask-mongoengine.
Unfortunately the fix seems not to work with flask-admin where "None" appears as the default string value in email fields (when creating new records); moreover, even if you remove the default vaule by hand, the validation fails when model save is attempted.
from flask-mongoengine.
from flask import Flask
from flask.ext import admin
from flask.ext.admin.contrib.mongoengine import ModelView
from flask.ext.mongoengine import MongoEngine
db = MongoEngine()
class TestDocument( db.Document ):
email = db.EmailField( required = False )
app = Flask( __name__ )
app.config[ 'SECRET_KEY' ] = '123456790'
app.config['MONGODB_SETTINGS'] = {'DB': 'testing'}
db.init_app( app )
adm = admin.Admin( app, 'TestCase' )
adm.add_view( ModelView( TestDocument ) )
if __name__ == '__main__':
app.run()
from flask-mongoengine.
from flask-mongoengine.
from flask-mongoengine.
Observe that in the first screenshot is the model validation that fails during save (after I submitted a form with empty email – the "None" you see has been re-added with the flashed message), while in the second example is the form validation that fails (because the field contains a wrong "default" value).
from flask-mongoengine.
Please open a new ticket @mapio and ill fix for 0.7
from flask-mongoengine.
Thank you @rozza, I just added issue #44.
from flask-mongoengine.
Related Issues (20)
- Mongo Debug Toolbar Panel: Update HTML view to enable scrolling
- Mongo Debug Toolbar Panel: Update HTML view to use wide screens
- Test database stays in place after tests!
- Add docs to new connection module #429 and new installation #475 HOT 1
- Migration to 2.0.0 documentation HOT 1
- Include Pillow as extra option for ImageField support?
- Ensure typing statements will not cause strong dependency on Flask-Debug Panel or WTForms
- Incompatibility with current flask version (2.2) HOT 7
- MongoEngine models Field missing HOT 2
- DecimalField: pass places to widget?
- New JSONProvider use of super() not quite right HOT 1
- AttributeError: type object 'Collection' has no attribute 'insert' HOT 3
- MongoEngine saving to a database called 'test' instead of database specified HOT 1
- Regarding new release HOT 8
- Config `db` cover host info
- after configuring database getting error mongoengine.connection.ConnectionFailure: You have not defined a default connection
- Failing debug_toolbar from subdomain (under https loads static files with http - blocked by browser) HOT 1
- Flask2.3.X JSONEncoder deprecated HOT 7
- This is a dead project - DO NOT USE HOT 7
- New Fork
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flask-mongoengine.