[Django] #21019: force_text fails on class object with __unicode__ instance method

6 views
Skip to first unread message

Django

unread,
Sep 2, 2013, 3:32:40 AM9/2/13
to django-...@googlegroups.com
#21019: force_text fails on class object with __unicode__ instance method
----------------------------+------------------------
Reporter: drtyrsa | Owner: nobody
Type: Bug | Status: new
Component: Utilities | Version: 1.5
Severity: Normal | Keywords: force_text
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 1 | UI/UX: 0
----------------------------+------------------------
{{{
In [10]: class A(object):
def __unicode__(self):
pass
....:

In [11]: force_text(A)
---------------------------------------------------------------------------
TypeError Traceback (most recent call
last)
<ipython-input-13-f9169705858c> in <module>()
----> 1 force_text(A)

.../django/utils/encoding.pyc in force_text(s, encoding, strings_only,
errors)
97 if not isinstance(s, six.string_types):
98 if hasattr(s, '__unicode__'):
---> 99 s = s.__unicode__()
100 else:
101 if six.PY3:

TypeError: unbound method __unicode__() must be called with A instance as
first argument (got nothing instead)
}}}

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

Django

unread,
Sep 2, 2013, 3:44:49 AM9/2/13
to django-...@googlegroups.com
#21019: force_text fails on class object with __unicode__ instance method
----------------------------+--------------------------------------

Reporter: drtyrsa | Owner: nobody
Type: Bug | Status: new
Component: Utilities | Version: 1.5
Severity: Normal | Resolution:

Keywords: force_text | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

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


Comment:

https://github.com/django/django/pull/1543

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

Django

unread,
Sep 2, 2013, 3:44:55 AM9/2/13
to django-...@googlegroups.com
#21019: force_text fails on class object with __unicode__ instance method
----------------------------+--------------------------------------

Reporter: drtyrsa | Owner: nobody
Type: Bug | Status: new
Component: Utilities | Version: 1.5
Severity: Normal | Resolution:

Keywords: force_text | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

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


Comment:

https://github.com/django/django/pull/1543

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

Django

unread,
Sep 2, 2013, 3:45:20 AM9/2/13
to django-...@googlegroups.com
#21019: force_text fails on class object with __unicode__ instance method
----------------------------+--------------------------------------

Reporter: drtyrsa | Owner: nobody
Type: Bug | Status: new
Component: Utilities | Version: 1.5
Severity: Normal | Resolution:

Keywords: force_text | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

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


Comment:

https://code.djangoproject.com/ticket/21019

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

Django

unread,
Sep 2, 2013, 3:45:43 AM9/2/13
to django-...@googlegroups.com
#21019: force_text fails on class object with __unicode__ instance method
----------------------------+--------------------------------------
Reporter: drtyrsa | Owner: drtyrsa
Type: Bug | Status: assigned
Component: Utilities | Version: 1.5
Severity: Normal | Resolution:

Keywords: force_text | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* owner: nobody => drtyrsa
* needs_better_patch: => 0
* status: new => assigned


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


Comment:

https://code.djangoproject.com/ticket/21019

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

Django

unread,
Sep 2, 2013, 7:24:00 AM9/2/13
to django-...@googlegroups.com
#21019: force_text fails on class object with __unicode__ instance method
----------------------------+--------------------------------------
Reporter: drtyrsa | Owner: drtyrsa
Type: Bug | Status: closed
Component: Utilities | Version: 1.5
Severity: Normal | Resolution: invalid

Keywords: force_text | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* status: assigned => closed
* resolution: => invalid


Comment:

I think that calling `force_text` on the class itself is not a valid use
case, unless you can demonstrate the opposite.

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

Django

unread,
Sep 2, 2013, 8:03:59 AM9/2/13
to django-...@googlegroups.com
#21019: force_text fails on class object with __unicode__ instance method
----------------------------+--------------------------------------
Reporter: drtyrsa | Owner: drtyrsa
Type: Bug | Status: closed
Component: Utilities | Version: 1.5
Severity: Normal | Resolution: invalid

Keywords: force_text | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

Comment (by drtyrsa):

What are valid use cases for `smart_text` then? As I understand it takes
some object and returns its str (unicode) representation. Why can not this
object be class itself?

I am using it to log the args of the function (some args can be models
classes). Isn't it valid use case?

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

Django

unread,
Sep 3, 2013, 8:06:40 AM9/3/13
to django-...@googlegroups.com
#21019: force_text fails on class object with __unicode__ instance method
----------------------------+--------------------------------------
Reporter: drtyrsa | Owner: drtyrsa
Type: Bug | Status: closed
Component: Utilities | Version: 1.5
Severity: Normal | Resolution: invalid

Keywords: force_text | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

Comment (by claudep):

Currently, `force_text`/`smart_text` are meant to receive instances, not
classes. I'd say that for your specific use case, you may test your
argument before passing it to `force_text`, for example with the
`inspect.isclass` method.

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

Reply all
Reply to author
Forward
0 new messages