#24677: models.TextField cleaning doesn't behave the same as models.CharField. ----------------------------------------------+-------------------- Reporter: kezabelle | Owner: nobody Type: Bug | Status: new Component: Database layer (models, ORM) | Version: master Severity: Normal | Keywords: Triage Stage: Unreviewed | Has patch: 0 Easy pickings: 0 | UI/UX: 0 ----------------------------------------------+-------------------- 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 [https://github.com/django/django/blob/b5e0eede406633b88c6222031171f80876d8f5e1/django/db/models/fields/__init__.py#L2121 TextField implements `get_prep_value`] but not `to_python`, while `CharField` implements [https://github.com/django/django/blob/b5e0eede406633b88c6222031171f80876d8f5e1/django/db/models/fields/__init__.py#L1105 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 [https://github.com/kezabelle/django- strictmodels/commit/1acad9ef63769fc6378c6d023333259c2a8cc41f#diff- 4a6a4e7167b55119eefda4da703221edR160 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. -- Ticket URL: <https://code.djangoproject.com/ticket/24677> Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/052.e403f2dfab1b819b0da5291c57e58a57%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.