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

Documents _post_clean() does not handle None to EMPTY_VALUES conversion gracefully #65

Open
foxx opened this issue Apr 24, 2014 · 1 comment

Comments

@foxx
Copy link

foxx commented Apr 24, 2014

If the DocumentForm has an optional StringField with no data value specified for it on the form instance, it will fail with;

StringField only accepts string values

This is because on documents.py#L439, a call is being made to validate() on the model field which in raises an exception.

Mongoengine handles this in save() by simply removing the field during to_mongo() as seen in mongoengine:document.py#L248.

Here's a few ideas on how it could be fixed;

  • Prevent .validate() from being called on fields which are not specified in data
  • Ignore any validation errors if the field is optional and the value is None
  • Convert None to the necessary 'empty value' required for each field type
  • Modify _get_validation_exclusions() to support excluding this condition

All of the above could have cascading consequences, and it's not clear which is the correct way forward.

Thoughts?

@Karmak23
Copy link

Karmak23 commented Oct 8, 2014

I have a problem which seems related.

Stacktrace: http://dev.1flow.net/development/1flow-dev/group/44097/

My code:

class Feed(Document):
    …
    thumbnail_url  = URLField(required=False, default=u'')
    …

…

class FeedAdminForm(DocumentForm):
    class Meta:
        model = Feed

It crashes, but only in the Django admin.
I use Django 1.6.
This happens whether default=u'' is present or not. Django keeps wanting to convert u'' to None and it crashes.

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

2 participants