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

NoneBlankField does not work with flask-admin (i.e. prevents validation of EmailField) #44

Closed
mapio opened this issue May 2, 2013 · 6 comments
Milestone

Comments

@mapio
Copy link
Contributor

mapio commented May 2, 2013

The fix described in #9 seems to break flask-admin.

More precisely, given the following test case

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()

If one tries to create a new record None appears as the default value for the email field – this is a first bug.

If a save is attempted a form validation error happens (since, of course, None is not a valid email address):

dece3c02-b331-11e2-8d5d-888356aa6e42

In the case the field is first cleaned (leaving it empty) and then saved, a model validation happens – this is a second bug, given that if the forms validate, the model should also:

screen shot 2013-05-02 at 4 04 40 pm

(observe that in the screenshot None reappeared as the field value, even if it was empty before the save button was hit).

@rozza
Copy link
Contributor

rozza commented May 3, 2013

Fixed!

@rozza rozza closed this as completed May 3, 2013
@rozza
Copy link
Contributor

rozza commented May 3, 2013

Fixed in 0.7 I should say!

@rozza
Copy link
Contributor

rozza commented May 3, 2013

Although - Flask-SuperAdmin doesn't use NoneBlankField...

rozza added a commit that referenced this issue May 3, 2013
@mapio
Copy link
Contributor Author

mapio commented May 3, 2013

First of all, thank you @rozza for the very fast fix!

I'm afraid I've to bother you again, observing that if you take the above testcase and replace EmailField with URLField you incur in a very similar error: no None appears as default value, but submitting a form with an empty URL results in a model validation failure…

Do you want me to submit a new issue?

rozza added a commit that referenced this issue May 3, 2013
@rozza
Copy link
Contributor

rozza commented May 3, 2013

@mapio no problems updated it to use NoneStringField as well

@01walid
Copy link

01walid commented Feb 25, 2014

I think this is not fixed, yet.... or maybe just partially
try to make unique=True and required=False to see what I mean
it will consider empty string as unique!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants