Re: Help debugging a script that is using ZODB.

Jason Madden <[email protected]> Mon, 11 May 2020 09:20:14 -0500
Newsgroups gmane.comp.web.zope.zodb
Message-ID <[email protected]>

> On May 11, 2020, at 01:01, Michael Howitz <[email protected]> wrote:
>=20
> Hi!
>=20
> Am 09.05.2020 um 17:57 schrieb [email protected]:
>> I am trying to debug a script that is using ZODB. It is hard to tell if =
some of the methods are functioning correctly because the information the d=
ebugger displays does not tell me worthwhile information. Information such =
as "<__main__.Coord object at 0x00000000147FA908 oid 0x1185 in <Connection =
at 03c395c0>>" is displayed in the debugger, but it doesn't tell me informa=
tion that is useful while debugging. I would like to know the safe way of c=
hanging what is displayed for a persistent object. I already tried adding a=
 "__str__" method, but that did not change the display. I am using python 3=
.7 with ZODB 5.5.1.
>=20
> You should add a __repr__ method to your Coord object returning the infor=
mation you need to debug. That method is called when printing the represent=
ation of an object.

For a bit of extra safety (especially if you're debugging POSKeyError and t=
he like), you could override `_p_repr` instead (https://persistent.readthed=
ocs.io/en/latest/api/interfaces.html):

> By default, persistent objects include the reprs of their `_p_oid` and `_=
p_jar`, if any, in their repr. If a subclass implements the optional method=
 `_p_repr`, it will be called and its results returned instead of the defau=
lt repr; if this method raises an exception, that exception will be caught =
and its repr included in the default repr.

--=20
You received this message because you are subscribed to the Google Groups "=
zodb" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/=
zodb/7B66EB04-25F3-4A99-8620-B716FDEB20F6%40nextthought.com.