{{{
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.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
Related to #20440.
--
Ticket URL: <https://code.djangoproject.com/ticket/24818#comment:1>
* has_patch: 0 => 1
Comment:
Pull request https://github.com/django/django/pull/4676
--
Ticket URL: <https://code.djangoproject.com/ticket/24818#comment:2>
--
Ticket URL: <https://code.djangoproject.com/ticket/24818#comment:3>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/24818#comment:4>
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>
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>
* cc: slamora (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/24818#comment:7>
* 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>