This replaces the default "<XYClass object at 0xdeadbeeff00>" repr() for DB objects, which is pretty useless. This change makes it easier to identify DB objects in debuggers (and logs, if objects get logged). __repr__() and __str__() have slightly different purposes. The purpose of __repr__() is to return a string that uniquely identifies a single object. __str__(), on the other hand, should produce a human readable string. Another thing that is worth to note is that str() will call __repr__() if __str__() is not implemented, repr() will always call __repr__(). More details can be found under [1]. By implementing a generic __repr__() in the base class there should be no need to override it in the models classes. However, one might not be interested in seeing all the object's attributes in a string representation (which is what the generic __repr__() would do) or certain sensitive information should be hidden from users. In those cases it makes sense to implement __str__() for certain classes specifically. Release notes were taken from a follow-up change [2]. [1]: https://stackoverflow.com/a/2626364/6265131 [2]: I9b9eb3158b099cf04d788692fc9e5efcdfebf93e Change-Id: I4c218793948b0ed7ce0c143d6c794516fdeb224f (cherry picked from commitff6d0c5280) (cherry picked from commit2cb52fe60a) (cherry picked from commit9ed984f861)
8 lines
316 B
YAML
8 lines
316 B
YAML
---
|
|
other:
|
|
- |
|
|
The string representation of data base model objects has been improved.
|
|
Calling str() on them will return a certain subset of fields and calling
|
|
repr() on them will return all fields. This is helpful for debugging, but
|
|
it may also change some of the log messages that Octavia emits.
|