Opened 18 years ago
Closed 17 years ago
#4733 closed (invalid)
Allowing blank inserts in models.Charfield
Reported by: | Ceschiatti | Owned by: | Adrian Holovaty |
---|---|---|---|
Component: | Validators | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
A have a model wieh a models.Charfield. Django is allowing my app to insert a model with this field blank, even if I put the option blank = False in it (though the default is False). I'm using version 0.97-pre (SVN).
Change History (4)
comment:1 by , 18 years ago
comment:2 by , 17 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
marked as invalid until the requested info is provided.
comment:3 by , 17 years ago
Resolution: | invalid |
---|---|
Status: | closed → reopened |
I have exactly the same beaviour on my model and consider it a serious bug to be honest. Here is how I can reproduce it.
Here is my model I use. It even doesn't matter if I use blank=False on the name attribute.
class Project(models.Model): name = models.CharField(_('Projektname'), max_length = 255) description = models.TextField(_('Beschreibung'), max_length = 64000, blank=True) active = models.BooleanField(_('Aktiv?'), default = True) owner = models.ForeignKey(User, verbose_name=_('Eigentümer')) class Meta: unique_together = [('name', 'owner')] verbose_name = _('Projekt') verbose_name_plural = _('Projekte') ordering = ['name'] class Admin: fields = [(None, { 'fields': ('name', 'owner', 'description', 'active') })] list_display = ['owner', 'name', 'active'] list_display_links = ['name'] list_filter = ['active'] search_fields = ['name'] def __unicode__(self): return self.name
And here is what I get in an interactive session.
>>> u = User.objects.get(username__exact="oa") >>> p = Project(owner = u) >>> p.validate() {'name': [u'This field is required.']} >>> p.save()
This must be an error in my eyes, cause it lets you insert invalid data into the database using the ORM, but prohibit it through the admin interface. And it can't also be DRY to actually require a call for validate before a save. At least that is, what I expect from it. ;)
I am also using the SVN version of Django.
comment:4 by , 17 years ago
Resolution: | → invalid |
---|---|
Status: | reopened → closed |
Validation and saving are intentionally separate, as noted elsewhere. The behaviour you are seeing is consistent with this design constraint and so this is not a bug, in that respect.
With the new validation code that is being added soon, I think we decided on some sort of option to have a save-and-validate all in one step, but I can't remember for sure. It won't be compulsory, but a shortcut might exist.
For right now, though, this remains "not a bug". Please don't reopen it just because you happen not to agree with that.
What steps are you taking to trigger this behaviour? Please provide a step-by-step example, since I can't repeat it with normal actions.
Note that if you just put an empty string into the field and then call save() on the model without doing any validation, that is not a bug, since save() does not do any validation by design (so that save() will never raise a validation error).