#14094: Cannot define CharField with unlimited length
----------------------------+-----------------------------------------------
Reporter: millerdev | Owner: nobody
Status: new | Milestone:
Component: Core framework | Version: 1.2
Keywords: | Stage: Unreviewed
Has_patch: 0 |
----------------------------+-----------------------------------------------
Model validation throws an error on CharField with a null max_length:
{{{
#!python
class Test(Model):
char_field = CharField(max_length=None)
}}}
'''
One or more models did not validate:[[BR]]
test.test: "char_field": CharFields require a "max_length" attribute that
is a positive integer.
'''
CharField should allow max_length=None, which intuitively means there is
no maximum length. This is a perfectly valid use case. Postgres, for
example, supports varchar/text columns without a length limit, but Django
appears to have no way to define such a column in a model class.
The model validation code looks like this
([http://code.djangoproject.com/browser/django/tags/releases/1.2.1/django/core/management/validation.py#L40
django/core/management/validation.py:40]):
{{{
#!python
if isinstance(f, models.CharField):
try:
max_length = int(f.max_length)
if max_length <= 0:
e.add(opts, '"%s": CharFields require a "max_length"
attribute that is a positive integer.' % f.name)
except (ValueError, TypeError):
e.add(opts, '"%s": CharFields require a "max_length" attribute
that is a positive integer.' % f.name)
}}}
It should be changed to something this:
{{{
#!python
if isinstance(f, models.CharField) and f.max_length is not None:
...
}}}
The FileField does not happen to throw this error because it is not a
derivative of CharField. However, the SQL generated for FileField is not
correct when max_length=None, so that would need to be addressed as well.
--
Ticket URL: <http://code.djangoproject.com/ticket/14094>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.