[Zope] monkey patches and persistence
Dennis Allison
allison at sumeru.stanford.EDU
Tue Dec 30 20:39:38 EST 2003
I have a monkey patch I am using with User Folder (I have multiple
acl_user instances which are selected dynamically as needed.). I'm seeing
some behavior that could be explained by persistence problems. I'd
appreciate it if someone would review my approach here to see if I've
missed something. Suggestions for a different approach would also be
appreciated.
I have a Product, "MyUserFolder", which incorporates a number of methods
which override methods in the Zope UserFolder and/or add new methods.
MyUserFolder consists of a single __init__.py. which includes the
necessary imports and definitions of the new methods:
from AccessControl.User import User
def foo( self, param1, param2 ):
....
and then patches them in with
if 1:
from Globals import InitializeClass
from AccessControl.User import UserFolder
# Monkey-patch the original class by
# reassigning method references
UserFolder.foo = foo
# re-initialize the class
InitializeClass( UserFolder )
When a compound data structure (e.g., a dictionary of dictionaries) is
modified in a method, for example, foo, the change is flagged by including
the statement
self._p_changed = 1
is incorporated in the method body.
What I observe is the following:
Conceptually, the acl_users structure is replaced with a dictionary of
acl_users instances, the particular one being selected by a key maintained
as a session variable. This works just fine, most of the time. But,
occasionally, the acl_users data in one of the instances, just disappears.
My suspicion is that the date in the acl_users instance is not being
picked up by the persistence mechanism, but I am at a loss to locate the
problem.
Comments, help much appreciated.
More information about the Zope
mailing list