Make Model.__repr__() safe
|Reported by:||Patryk Zawadzki||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||master|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
__repr__ is mainly used in the debugging context and it calling
__unicode__ can yield unwanted consequences such as executing a database query. I also propose having it include the primary key of the object so it's easy to track the record in the database.
__unicode__ is not really suitable for lookup, even if it returns contents of an actual database field in most cases it will be an unindexed column.
Please note that while having a more verbose
__repr__ can be useful, you can always overload this method in your models.
There is a pull request on GitHub that implements
__repr__ the following way:
Change History (6)
comment:1 Changed 4 years ago by
|Triage Stage:||Unreviewed → Accepted|
|Type:||Uncategorized → Cleanup/optimization|