Object identity and misleading default __repr__

Bug #1087138 reported by Marius Gedminas
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
ZODB Browser
Fix Released
Low
Unassigned

Bug Description

I received a bug report via email where the reporter was confused by two links to the same persistent object having different titles (of the form '<package.module.Class object at 0xabcde>' with different memory addresses).

What was more confusing to me was seeing a list of references to different persistent objects all having the same representation:
['<package.module.Class object at 0xsame', '<package.module.Class object at 0xsame', ...]

This happens because the same memory address is reused when we free one Persistent object and load the next one.

Idea: check if the object has a custom __repr__ (via obj.__repr__.im_func is object.__repr__.im_func). If so, use a custom one. For instances of Persistent we could use

    '<%s.%s with oid %x>' % (obj.__class__.__module__, obj.__class__.__name__, u64(obj._p_oid))

I haven't made up my mind if it make sense to hide the memory address of non-persistent objects. On the one hand, all non-persistent objects are different if they're loaded from different pickles. On the other hand, it's possible to have multiple references to the same persistent object within one pickle.

Changed in zodbbrowser:
status: Triaged → Fix Committed
milestone: none → 0.10.3
Revision history for this message
Marius Gedminas (mgedmin) wrote :

The fix in 0.10.3 was bad. 0.10.4 will have a proper fix.

Changed in zodbbrowser:
milestone: 0.10.3 → 0.10.4
Changed in zodbbrowser:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.