Skip to content

Make Model.__repr__() safe #1108

Closed
wants to merge 1 commit into from

3 participants

@patrys
patrys commented May 18, 2013

__repr__ is mainly used in the debugging context and it calling __unicode__ can yield unwanted consequences such as executing a database query (I guess it's a common thing with translated objects).

This implementation also makes it easier to find the object in the database as it displays its primary key which is the only field we can assume to be indexed.

All tests pass.

@patrys patrys Make Model.__repr__ safe
__repr__ is mainly used in the debugging context and it calling
__unicode__ can yield unwanted consequences such as executing a database
query (I guess it's a common thing with translated objects).

This implementation also makes it easier to find the object in the
database as it displays its primary key which is the only field we can
assume to be indexed.
18d56b5
@agafonovdmitry

Useful change!

@mjtamlyn
Django member

This change will need a ticket. Personally I'm unconvinced by the change, I use the fact this has the __unicode__ in it all the time. It probably warrants a discussion on django-dev mailing list.

@mjtamlyn mjtamlyn closed this May 18, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.