[Django] #24818: models.CharField shouldn't accept a string as max_lenght

1 view
Skip to first unread message

Django

unread,
May 19, 2015, 4:57:04 AM5/19/15
to django-...@googlegroups.com
#24818: models.CharField shouldn't accept a string as max_lenght
----------------------------------------------+--------------------
Reporter: slamora | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
In models.CharField you can define max_length as string and the system
check framework doesn't complain ([https://groups.google.com/forum/#!msg
/django-users/GS19FwbYfCI/qZXBX3cI2jsJ related mailing list thread]):

{{{
from django.db import models

class Foo(models.Model):
bar = models.CharField(max_length='16')
}}}

{{{
>>> # following code raises an Exception
>>> obj = Foo(bar='lorem ipsum')
>>> obj.clean_fields()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python3.4/dist-packages/django/db/models/base.py",
line 1167, in clean_fields
setattr(self, f.attname, f.clean(raw_value, self))
File "/usr/local/lib/python3.4/dist-
packages/django/db/models/fields/__init__.py", line 589, in clean
self.run_validators(value)
File "/usr/local/lib/python3.4/dist-
packages/django/db/models/fields/__init__.py", line 541, in run_validators
v(value)
File "/usr/local/lib/python3.4/dist-packages/django/core/validators.py",
line 280, in __call__
if self.compare(cleaned, self.limit_value):
File "/usr/local/lib/python3.4/dist-packages/django/core/validators.py",
line 319, in <lambda>
compare = lambda self, a, b: a > b
TypeError: unorderable types: int() > str()
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24818>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 19, 2015, 4:58:59 AM5/19/15
to django-...@googlegroups.com
#24818: models.CharField shouldn't accept a string as max_lenght
-------------------------------------+-------------------------------------

Reporter: slamora | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by slamora):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Related to #20440.

--
Ticket URL: <https://code.djangoproject.com/ticket/24818#comment:1>

Django

unread,
May 19, 2015, 5:49:54 AM5/19/15
to django-...@googlegroups.com
#24818: models.CharField shouldn't accept a string as max_lenght
-------------------------------------+-------------------------------------

Reporter: slamora | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by alasdairnicol):

* has_patch: 0 => 1


Comment:

Pull request https://github.com/django/django/pull/4676

--
Ticket URL: <https://code.djangoproject.com/ticket/24818#comment:2>

Django

unread,
May 19, 2015, 5:50:11 AM5/19/15
to django-...@googlegroups.com
#24818: models.CharField shouldn't accept a string as max_length
-------------------------------------+-------------------------------------

Reporter: slamora | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

--
Ticket URL: <https://code.djangoproject.com/ticket/24818#comment:3>

Django

unread,
May 19, 2015, 5:51:38 AM5/19/15
to django-...@googlegroups.com
#24818: models.CharField shouldn't accept a string as max_length
-------------------------------------+-------------------------------------

Reporter: slamora | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by alasdairnicol):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/24818#comment:4>

Django

unread,
May 19, 2015, 5:56:36 AM5/19/15
to django-...@googlegroups.com
#24818: models.CharField shouldn't accept a string as max_length
-------------------------------------+-------------------------------------

Reporter: slamora | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by bmispelon):

Is there a reason why we can't cast `max_length` to an integer value in
`Field.__init__`?

--
Ticket URL: <https://code.djangoproject.com/ticket/24818#comment:5>

Django

unread,
May 19, 2015, 7:10:43 AM5/19/15
to django-...@googlegroups.com
#24818: models.CharField shouldn't accept a string as max_length
-------------------------------------+-------------------------------------

Reporter: slamora | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by slamora):

Replying to [comment:5 bmispelon]:


> Is there a reason why we can't cast `max_length` to an integer value in
`Field.__init__`?

Because that will mask the real "problem" as has happened with the current
implementation that casts {{{ mask_length }}} at {{{
_check_max_length_attribute }}}.

IMHO, Django shouldn't handle user's fault but warn the user about it.

--
Ticket URL: <https://code.djangoproject.com/ticket/24818#comment:6>

Django

unread,
May 19, 2015, 7:12:38 AM5/19/15
to django-...@googlegroups.com
#24818: models.CharField shouldn't accept a string as max_length
-------------------------------------+-------------------------------------

Reporter: slamora | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by slamora):

* cc: slamora (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/24818#comment:7>

Django

unread,
May 19, 2015, 8:08:31 AM5/19/15
to django-...@googlegroups.com
#24818: models.CharField shouldn't accept a string as max_length
-------------------------------------+-------------------------------------
Reporter: slamora | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"d091b75eefcd02872f7d45e9f5f5dd2fa719bbff" d091b75]:
{{{
#!CommitTicketReference repository=""
revision="d091b75eefcd02872f7d45e9f5f5dd2fa719bbff"
Fixed #24818 -- Prevented models.CharField from accepting a string as
max_length
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24818#comment:8>

Reply all
Reply to author
Forward
0 new messages