Opened 11 years ago

Closed 8 years ago

#20222 closed Bug (fixed)

Some functions are wrapped into allow_lazy incorrectly

Reported by: Alexey Boriskin Owned by: Baptiste Mispelon
Component: Utilities Version: dev
Severity: Normal Keywords:
Cc: bmispelon@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

allow_lazy() requires more than one argument. Second and further arguments must be types.
There are a few functions which are wrapped into allow_lazy without *resultclasses specified.
Namely:

  • django.utils.html.strip_tags
  • django.utils.text.Truncator.chars
  • django.utils.text.Truncator.words
  • django.utils.text.recapitalize
  • django.utils.text.phone2numeric
  • django.utils.text.unescape_string_literal

IPython session, which demonstrates code broken because of that:

In [1]: from django.utils.functional import lazy
In [2]: from django.utils.encoding import force_text
In [3]: from django.utils import six
In [4]: from django.utils.html import strip_tags
In [5]: promise = lazy(lambda:u'hello', six.text_type)()
In [6]: force_text(promise)
Out[6]: u'hello'
In [7]: promise = lazy(lambda:u'hello', six.text_type)()
In [8]: stripped = strip_tags(promise)
In [9]: force_text(stripped)
Out[9]: u'<django.utils.functional.__proxy__ object at 0x101f6ca50>'

Change History (9)

comment:1 by Alexey Boriskin, 11 years ago

Thanks to bmispelon for pointing that out.

comment:2 by Baptiste Mispelon, 11 years ago

Cc: bmispelon@… added
Easy pickings: set
Triage Stage: UnreviewedAccepted

comment:3 by Baptiste Mispelon, 11 years ago

Owner: changed from nobody to Baptiste Mispelon
Status: newassigned

I've started working on this on my branch: https://github.com/bmispelon/django/compare/allow-lazy-refactor

I hope to fix #20221 and #20223 along with this one.

comment:4 by Baptiste Mispelon, 11 years ago

I've prepared a pull request for this ticket that include fixes for 3 other ones: https://github.com/django/django/pull/1007

comment:5 by Tom Mortimer-Jones, 11 years ago

Has patch: set

comment:6 by Tim Graham, 10 years ago

Easy pickings: unset
Patch needs improvement: set

No longer merges cleanly.

comment:7 by Alexey Boriskin, 9 years ago

Patch needs improvement: unset

I've updated bmispelon's patch so it merges cleanly as a pull request 4202:
https://github.com/django/django/pull/4202

comment:8 by Tim Graham, 9 years ago

Patch needs improvement: set

Comments for improvement on the PR.

comment:9 by Tim Graham, 8 years ago

Resolution: fixed
Status: assignedclosed

Correct me if I'm wrong, but based on the sample shell session, I think this is fixed by #25000.

Note: See TracTickets for help on using tickets.
Back to Top