Opened 15 years ago

Closed 15 years ago

#12223 closed (invalid)

Model field documentation needs clarification about validation

Reported by: JohnDoe Owned by: nobody
Component: Database layer (models, ORM) Version: 1.1
Severity: Keywords: validation
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The modelfield EmailField does not actually validate the email, as stated in the documentation (see. http://docs.djangoproject.com/en/dev/ref/models/fields/#emailfield).

My test

class TestModel(models.Model):
    email = models.EmailField()
>>> t = TestModel(email='asd,,,')
>>> t.save()

No error is raised, even though that is not a valid email.

Change History (6)

comment:1 by James Bennett, 15 years ago

Resolution: invalid
Status: newclosed

Models do not currently do any validation; that's what forms are for, and the default form field generated by EmailField does indeed implement a validation check.

comment:2 by JohnDoe, 15 years ago

That's not what the documentation states, it says:

A CharField that checks that the value is a valid e-mail address.

which does NOT happen.

So, either the documentation is wrong or the implementation of it must be.

comment:3 by James Bennett, 15 years ago

The implementation is not wrong, and the documentation is not wrong. Model fields never perform any validation of this sort, and at the moment are quite incapable of doing so. Forms can and do perform such validation, and when a form is generated from a model which includes an EmailField, the appropriate validation will be performed. Whenever and wherever a model field has specialized constraints like this, the validation is always handled by forms, and every such model field generates an appropriate form field which performs that validation.

comment:4 by bitspace, 15 years ago

Resolution: invalid
Status: closedreopened
Summary: EmailField does not actually validateModel field documentation needs clarification about validation

The documentation needs clarification as I also expected the model field to perform validation. Google revealed this ticket for me.

There really needs to be a "gotcha" prominently in the documentation that says what you said: "Whenever and wherever a model field has specialized constraints like this, the validation is always handled by forms, and every such model field generates an appropriate form field which performs that validation."

comment:5 by rbanffy, 15 years ago

Keywords: validation added

Shoudn't EmailField have something like the "verify_exists" attribute of the URLField? At least a "verify_wellformedness" or "check_if_it_looks_like_an_email" that could employ the django.core.validators stuff.

in reply to:  4 comment:6 by jkocherhans, 15 years ago

Resolution: invalid
Status: reopenedclosed

Replying to bitspace:

The documentation needs clarification as I also expected the model field to perform validation. Google revealed this ticket for me.

There really needs to be a "gotcha" prominently in the documentation that says what you said: "Whenever and wherever a model field has specialized constraints like this, the validation is always handled by forms, and every such model field generates an appropriate form field which performs that validation."

There are already several such warnings (though they may not have been there at the time this ticket was opened.) Keeping in mind that we're not going to add a warning to every single field's documentation, if you can point out a specific place where you'd expect to see a warning, please feel free to reopen this ticket.

Note: See TracTickets for help on using tickets.
Back to Top