I am using the standalone zodbbrowser 0.11.1 with a ZODB3 database. I can access the database fine but when I insert objects of unknown type into the ZODB the browser only displays:
Attributes
data: {u'account-1': <persistent broken __main__.Account instance '\x00\x00\x00\x00\x00\x00\x00\x01'>,
u'account-2': <persistent broken __main__.Account instance '\x00\x00\x00\x00\x00\x00\x00\x01'>
}
I'd like to see a formatted printout from __repr__ (or __str__) instead. The short user guide on pypi at Help! Broken objects everywhere recommends to make sure your application objects are importable from the Python path. But I don't know how.
How do I make the Account class (from the tutorial):
class Account(Persistent):
def __init__(self):
...
known to zodbbrowser in standalone mode so that the persistent broken type are replaced with a __str__ representation of the object instance?
To answer the question generally:
The easiest way would be to pip install zodbbrowser
into the same virtualenv you used for your ZODB application that created the database in question. This assumes you use virtualenv.
The second easiest way would be to add zodbbrowser
to the list of eggs in buildout.cfg
in the buildout you used for your ZODB application that created the database in question. This assumes you use zc.buildout.
Finally, you can try to set PYTHONPATH so that the module you used to create the persistent objects is importable.
None of the above will help your specific case, because the persisted objects thing they belong to the module called __main__
. That's a bad idea! There's only one __main__
in every Python invocation, and it depends on the script you run. If that script is zodbbrowser, then it can't also be your application.
For best results don't define any Persistent subclasses in your main script. Always define them in a separate module and import them.
However, if you already have such a database, and need to access the objects for forensic purposes or whatnot, there's a possible workaround:
write a new script, say, myzodbbrowser.py
, that looks something like this:
from myapp import Account # replace myapp with the script name of your app
import zodbbrowser.standalone
zodbbrowser.standalone.main()
run it with the Python from your virtualenv or buildout, where you installed zodbbrowser.