Help debugging a script that is using ZODB.

35 views
Skip to first unread message

animus...@gmail.com

unread,
May 9, 2020, 1:44:26 PM5/9/20
to zodb
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 debugger 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 information that is useful while debugging. I would like to know the safe way of changing 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.

Michael Howitz

unread,
May 11, 2020, 9:51:04 AM5/11/20
to animus...@gmail.com, zodb
Hi!

Am 09.05.2020 um 17:57 schrieb animus...@gmail.com:
> 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 debugger 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 information that is useful while debugging. I would like to know the safe way of changing 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.

You should add a __repr__ method to your Coord object returning the information you need to debug. That method is called when printing the representation of an object.


--
Mit freundlichen Grüßen
Michael Howitz

signature.asc

Jason Madden

unread,
May 11, 2020, 10:20:18 AM5/11/20
to Michael Howitz, animus...@gmail.com, zodb
For a bit of extra safety (especially if you're debugging POSKeyError and the like), you could override `_p_repr` instead (https://persistent.readthedocs.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 default repr; if this method raises an exception, that exception will be caught and its repr included in the default repr.

animus...@gmail.com

unread,
May 12, 2020, 7:55:09 PM5/12/20
to zodb
Thanks for all the help.
Reply all
Reply to author
Forward
0 new messages