[Zope] monkey patches and persistence

Dennis Allison allison at sumeru.stanford.EDU
Wed Dec 31 00:55:28 EST 2003


Brian, 
Thanks, I think you have spotted the problem.  A bit of reimplementation
and testing will tell, but there is one dictionary that should have been a
PersistentMapping.

On Tue, 30 Dec 2003, Brian Lloyd wrote:

> Taking a wild guess here, but I'd bet that a user folder is
> being modified in a way that doesn't go through one of your
> monkey-patched methods, which causes the changes to be lost
> if the chain of persistence isn't being maintained.
> 
> If it is feasible, I'd say that the best fix would be to
> use a PersistentMapping or a BTree instead of a plain dict
> to manage your collection of user folders. That should
> ensure that the changes are saved without your having to
> track / override every method that could possible change
> the state of a user or user folder.
> 
> hth,
> 
> 
> Brian Lloyd        brian at zope.com
> V.P. Engineering   540.361.1716
> Zope Corporation   http://www.zope.com
> 
> 
> > -----Original Message-----
> > From: zope-bounces at zope.org [mailto:zope-bounces at zope.org]On Behalf Of
> > Dennis Allison
> > Sent: Tuesday, December 30, 2003 8:40 PM
> > To: zope at zope.org
> > Subject: [Zope] monkey patches and persistence
> >
> >
> >
> > 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.
> >
> >
> > _______________________________________________
> > Zope maillist  -  Zope at zope.org
> > http://mail.zope.org/mailman/listinfo/zope
> > **   No cross posts or HTML encoding!  **
> > (Related lists -
> >  http://mail.zope.org/mailman/listinfo/zope-announce
> >  http://mail.zope.org/mailman/listinfo/zope-dev )
> >
> 




More information about the Zope mailing list