home / django_tickets / tickets

tickets: 14094

This data as json

id created changetime last_pulled_from_trac stage status component type severity version resolution summary description owner reporter keywords easy has_patch needs_better_patch needs_tests needs_docs ui_ux
14094 2010-08-11 13:59:39 2019-05-03 17:19:28 2022-03-06 03:56:59.156957 Accepted assigned Database layer (models, ORM) New feature Normal dev   Cannot define CharField with unlimited length 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. ar45 millerdev   0 1 1 0 0 0
Powered by Datasette · Queries took 1.135ms