Opened 11 years ago

Closed 11 years ago

#22856 closed Bug (invalid)

Blank=False not being enforced

Reported by: fongandrew2 Owned by: nobody
Component: Uncategorized Version: 1.7-beta-2
Severity: Normal 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

It is possible to save a blank value to CharField(blank=False) without Django raising any exception.

from django.db import models

# Create your models here.
class MyModel(models.Model):
    my_charfield = models.CharField(max_length=32, blank=False)

# This should fail, but it does not
MyModel().save()

Attachments (1)

testproj.zip (3.4 KB ) - added by fongandrew2 11 years ago.
Simple testcase reproducing issue

Download all attachments as: .zip

Change History (2)

by fongandrew2, 11 years ago

Attachment: testproj.zip added

Simple testcase reproducing issue

comment:1 by Carl Meyer, 11 years ago

Resolution: invalid
Status: newclosed

Thanks for the report, but this is working as designed. The blank parameter is only for validation, and validation is not done automatically by save(). The reason for the latter is that in the general case it can't be assumed that the caller of save() is in a position to catch and handle validation errors. If you want your model data validated before saving, you should call full_clean().

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