[Zope-dev] [Solved] Cannot load state: None has no attribute 'load'
Dieter Maurer
dieter@handshake.de
Wed, 15 Aug 2001 07:56:43 +0200 (CEST)
Recently, I reported a strange effect where Zope suddenly
and without apparent reason reports lots of
"Could not load state: None object has no attribute 'load'.
I think, I now understand why this happens and can work around it:
We use GUF (Generic User Folder) to maintain users in
an Oracle database. Although Oracle is quite fast
with the kind of queries involved in authentication
(with others it is extremely slow), the complete
authentication process was slow: 0.2 to 0.5 seconds
I wanted to improve on this and implemented a user cache.
For simplicity and speed I cached the completely wrapped
user object.
Not a good idea, if one thinks carefully about it!
Apparently, everything worked well, but suddenly, non-deterministically
after many hours, Zope reports "Could not load..." in the log
file and raises really erratic exceptions in Web requests....
What have I learned....
*NEVER* cache persistent objects (or objects referencing a
persistent one!).
They contain a hidden reference to the ZODB connection
that created them (and that is used to load subobjects that
have not yet been loaded).
This reference is valid only in the thread (and probably
also only the request) that made it.
Invalid uses can show very interesting effects, like
the above "Could not load...", "TypeError, 'Results' instances
do not support subscription", "AttributeError, '__len__'", .....
What will I do:
I will cache the bare non-persistent user object (after I scrapped
all acquisition wrappers). I will rewrap it into the
UserFolder context, when the cached object is looked up.
Special thanks to Chris for his help with the original problem report.
Dieter