Opened 4 years ago

Closed 3 years ago

#24781 closed Bug (fixed)

lazy() may need a __repr__ for Python 2

Reported by: jdh13 Owned by: Chesco Igual
Component: Utilities Version: 1.7
Severity: Normal Keywords: py2
Cc: Chesco Igual Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by Baptiste Mispelon)

in python2:

>>> from django.apps import apps
>>> apps.get_app_config('admin').verbose_name

displays:

<django.utils.functional.__proxy__ object at 0x2c24c10>

instead of name

Change History (11)

comment:1 Changed 4 years ago by Baptiste Mispelon

Component: UncategorizedDocumentation
Description: modified (diff)
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

(the doc is here: https://docs.djangoproject.com/en/dev/ref/applications/)

Interestingly, doing print(apps.get_app_config('admin').verbose_name) still gives a useless repr on python2 under 1.7.
On master or on Python 3, you get the expected behavior ("admin" is printed, or a translation in your active language).

comment:2 Changed 4 years ago by Baptiste Mispelon

For what it's worth (I'm not sure if there's an actual bug to be fixed here), I bisected the print issue to ea3e40c278eb27fb3c8362d9e8cd67f957bf4f57.

comment:3 Changed 4 years ago by Tim Graham

I think the root cause is related to #25000 (I could reproduce the issue on master with Python 2). Adding a __repr__() method similar to the __str__() method added in the linked ticket seems to fix the issue:

def __repr__(self):
    return repr(self.__cast())

Not entirely sure that's the proper solution.

comment:4 Changed 3 years ago by Tim Graham

Component: DocumentationUtilities
Keywords: python2 added
Summary: incorrect command in doc: Applicationslazy() may need a __repr__ for Python 2

comment:5 Changed 3 years ago by Tim Graham

Keywords: py2 added; python2 removed

comment:6 Changed 3 years ago by Carl Meyer

Easy pickings: set

comment:7 Changed 3 years ago by Philip James

Owner: changed from nobody to Philip James
Status: newassigned

comment:8 Changed 3 years ago by Chesco Igual

Owner: changed from Philip James to Chesco Igual

comment:9 Changed 3 years ago by Chesco Igual

Cc: Chesco Igual added
Has patch: set

comment:10 Changed 3 years ago by Carl Meyer

Triage Stage: AcceptedReady for checkin

comment:11 Changed 3 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In ffd1873:

Fixed #24781 -- Fixed repr() for lazy objects.

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