GithubHelp home page GithubHelp logo

Comments (12)

anemitz avatar anemitz commented on September 3, 2024

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.

lucasvo avatar lucasvo commented on September 3, 2024

@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.

lucasvo avatar lucasvo commented on September 3, 2024

@anemitz I comitted a fix: e55bf96

from flask-mongoengine.

thomasst avatar thomasst commented on September 3, 2024

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.

lucasvo avatar lucasvo commented on September 3, 2024

@thomasst merged the pull request. Though the same issue might come up for other field types.

from flask-mongoengine.

mapio avatar mapio commented on September 3, 2024

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.

mapio avatar mapio commented on September 3, 2024
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.

mapio avatar mapio commented on September 3, 2024

image

from flask-mongoengine.

mapio avatar mapio commented on September 3, 2024

image

from flask-mongoengine.

mapio avatar mapio commented on September 3, 2024

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.

rozza avatar rozza commented on September 3, 2024

Please open a new ticket @mapio and ill fix for 0.7

from flask-mongoengine.

mapio avatar mapio commented on September 3, 2024

Thank you @rozza, I just added issue #44.

from flask-mongoengine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.