Monkey patching and inheritance
I am using monkey patches to modify Zope. I modify UserFolder.py by providing replacements for a number of methods. These methods are simply defined in an __init__.py in a module in the product folder, MyUserFolder. The UserFolder class is imported, the new overriding methods defined, and, at the end, InitializeClass is imported from Globals, and the patched procedure names assigned to their correspondiong names in Userfolder namespace, and InitializeClass() called on the UserFolder. The new code is fairly cautious about persistence. Use is made of PersistentMapping and PersistentList for mutable structures. I've been having occasional crashes of the Zope system with a diagnostic AttributeError: Surrogate instance has no attribute '_p_oid' which I have finally traced to the UserFolder modifications! Apparently I have somehow broken the persistence mechanism in my monkeypatching. Advise on what the problem might be and how to repair it would be very helpful. -dra
a man goes to a doctor and the doctor asks whats the problem, 'doc it hurts when i do this', and the doc replies 'well don't do that' and the sends the man home. iotw, its always better not to monkey patch unless you have no alternative. userfolders are something that can be replaced soley by product code and migrated, so using monkeypatching here is unesc. wrt to the specific error, its hard to suggest much given the information given, surrogates in the core zope are generally used for database connections registering for transactions. by crash i assume you mean an exception gets raised. cheers, -kapil On Wed, 2004-01-14 at 16:47, Dennis Allison wrote:
I am using monkey patches to modify Zope.
I modify UserFolder.py by providing replacements for a number of methods. These methods are simply defined in an __init__.py in a module in the product folder, MyUserFolder.
The UserFolder class is imported, the new overriding methods defined, and, at the end, InitializeClass is imported from Globals, and the patched procedure names assigned to their correspondiong names in Userfolder namespace, and InitializeClass() called on the UserFolder.
The new code is fairly cautious about persistence. Use is made of PersistentMapping and PersistentList for mutable structures.
I've been having occasional crashes of the Zope system with a diagnostic
AttributeError: Surrogate instance has no attribute '_p_oid'
which I have finally traced to the UserFolder modifications! Apparently I have somehow broken the persistence mechanism in my monkeypatching.
Advise on what the problem might be and how to repair it would be very helpful.
-dra
participants (2)
-
Dennis Allison -
Kapil Thangavelu