-
-
Notifications
You must be signed in to change notification settings - Fork 485
Make CharField(blank=True) not be considered nullable #39
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
Conversation
The documentation on [blank](https://docs.djangoproject.com/en/2.1/ref/models/fields/#blank) says that it "will allow the entry of an empty value", which for a string is just a 0-length string. This patch allows `CharField(blank=True,...)` to no longer be considered `Optional`. closes typeddjango#38
Hmm, from my understanding, the django test that failed /should/ fail type checking... |
https://github.com/django/django/blob/master/django/db/models/fields/__init__.py#L620 I don't know. From my understanding of the code, |
Hmm, interesting. However, allowing a field that doesn't have class MyModel(models.Model):
field = models.CharField(max_length=1, blank=True)
MyModel(field=None).save()
# raises IntegrityError (in mysql): (1048, "Column 'field' cannot be null") |
I think Then, there will be no need for additional line in |
Let me know if you want me to format it differently, or move the test cases into say model_init.test or nullable_fields.test, but I think code-wise it should do what we're expecting. |
Looks good! The only thing, could be make two tests out of those three - one for |
…rlying type is str (unless `null=True`)
Thanks! |
The documentation on blank says that it "will allow the entry of an empty value", which for a string is just a 0-length string. This patch allows
CharField(blank=True,...)
to no longer be consideredOptional
.closes #38