Opened 10 years ago
Closed 9 years ago
#24677 closed Bug (fixed)
models.TextField cleaning doesn't behave the same as models.CharField.
Reported by: | Keryn Knight | Owned by: | Rolo |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | django@… | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
For brevity's sake, I'm avoiding constructing whole model instances below, but the issue remains the same when they are attached.
>>> from django.db.models.fields import CharField, TextField >>> CharField().to_python(1) u'1' # type: unicode >>> TextField().to_python(1) 1 # type: int
I'd expect that cleaning a TextField
ought to result in a str/promise/smart_text as with CharField. The issue arises I believe because TextField implements `get_prep_value` but not to_python
, while CharField
implements to_python which is called by get_prep_value
. Both fields seem to exhibit the same behaviour for the get_prep_value
:
>>> CharField().get_prep_value(1) u'1' # type: unicode >>> TextField().get_prep_value(1) u'1' # type: unicode
From a cursory play in my toy project, it seems like hoisting the TextField.get_prep_value
logic into to_python
and calling it from get_prep_value
like CharField
does would make the behaviour consistent.
Change History (6)
comment:1 by , 10 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 9 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 9 years ago
comment:4 by , 9 years ago
The test in that PR is using a CharField, however, its docstring mentions TextField.
comment:5 by , 9 years ago
alright, now the test uses TextField: https://github.com/wildfish/django/commit/461473873131141955882318aa577d5ba9de30bc
Have created a pull request - https://github.com/django/django/pull/4751