ZSQL Pluggable brains broke in later Zope, can't add instance attributes
I've been using a pluggable brain with ZSQL methods to inject an instance attribute, like this: class PackageEvent: """Package Event Pluggable Brain""" def __init__(self): """initialize""" self.__dict__['eday'] = self.eventday() # self.eday = self.eventday() # setattr(self,'eday',self.eventday()) <snip> The first method (using __dict__) used to work on 2.2, but now fails on 2.3.3 I've tried the commented out methods as well. I get an attributeError when any of the above three methods are encountered. I believe some new ExtensionClass magic is causing this to fail. Record.c is too complicated for me to figure out. Do I need a self.__of__() something to do this? I can't use an instance method because I need to use <dtml-if first-eday> in my DTML methods. <dtml-var first-eventday> fails of course because eventday is a bound method, not a string. Any suggestions? thanks Brad Clements, bkc@murkworks.com (315)268-1000 http://www.murkworks.com (315)268-9812 Fax netmeeting: ils://ils.murkworks.com AOL-IM: BKClements
Hi Brad, Is eventday acquired or something? ----- Original Message ----- From: "Brad Clements" <bkc@murkworks.com> To: <zope@zope.org> Sent: Thursday, July 05, 2001 1:14 PM Subject: [Zope] ZSQL Pluggable brains broke in later Zope, can't add instance attributes
I've been using a pluggable brain with ZSQL methods to inject an instance attribute, like this:
class PackageEvent: """Package Event Pluggable Brain""" def __init__(self): """initialize""" self.__dict__['eday'] = self.eventday() # self.eday = self.eventday() # setattr(self,'eday',self.eventday())
<snip>
The first method (using __dict__) used to work on 2.2, but now fails on 2.3.3
I've tried the commented out methods as well.
I get an attributeError when any of the above three methods are encountered.
I believe some new ExtensionClass magic is causing this to fail. Record.c is too complicated for me to figure out.
Do I need a self.__of__() something to do this?
I can't use an instance method because I need to use <dtml-if first-eday> in my DTML methods.
<dtml-var first-eventday> fails of course because eventday is a bound method, not a string.
Any suggestions?
thanks
Brad Clements, bkc@murkworks.com (315)268-1000 http://www.murkworks.com (315)268-9812 Fax netmeeting: ils://ils.murkworks.com AOL-IM: BKClements
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
On 5 Jul 2001, at 13:02, Chris McDonough wrote:
Is eventday acquired or something?
Sorry, here's the full class, eventtime is an SQL column class PackageEvent: """Package Event Pluggable Brain""" def __init__(self): """initialize""" self.eday = self.eventday() # setattr(self,'eday',self.eventday()) # self.__dict__['eday'] = self.eventday() def eventday(self): return DateTime(apply(time.mktime,self.eventtime.tuple()[:3]+(0,0,0,0,0,-1)))
I'm actually sort of surprised that it used to work at all.. I'd imagine that AttributeError is on the eventtime attr, right? Though I haven't looked at the code, from your description, it would seem that the pluggable brains stuff makes a class instance and then stuffs in the attrs... the __init__ method would get called at instantiation time before the class attrs existed, causing the attributeerror. Would it be possible to use an "init()" method on the brain object, a custom __getattr__, or a computed attribute (see http://debian.acm.ndsu.nodak.edu/doc/python-extclass/ExtensionClass.html , search for computed attribute) instead of trying to precompute the attr? You could cache the return value on the first call if you used a custom __getattr__ or a computed attribute. - C ----- Original Message ----- From: "Brad Clements" <bkc@murkworks.com> To: "Chris McDonough" <chrism@digicool.com> Cc: <zope@zope.org> Sent: Thursday, July 05, 2001 1:37 PM Subject: Re: [Zope] ZSQL Pluggable brains broke in later Zope, can't add instance attributes
On 5 Jul 2001, at 13:02, Chris McDonough wrote:
Is eventday acquired or something?
Sorry, here's the full class, eventtime is an SQL column
class PackageEvent: """Package Event Pluggable Brain""" def __init__(self): """initialize""" self.eday = self.eventday() # setattr(self,'eday',self.eventday()) # self.__dict__['eday'] = self.eventday()
def eventday(self): return DateTime(apply(time.mktime,self.eventtime.tuple()[:3]+(0,0,0,0,0,-1)))
On 5 Jul 2001, at 13:48, Chris McDonough wrote:
I'm actually sort of surprised that it used to work at all.. I'd imagine that AttributeError is on the eventtime attr, right?
Nope, I'm being denied the ability to put 'eday' into self.__dict__ Anyway, eventtime *is* already in self.__dict__ before the brain is created Traceback (innermost last): File /home/bkc/Development/lib/python/ZPublisher/Publish.py, line 223, in publish_module File /home/bkc/Development/lib/python/ZPublisher/Publish.py, line 187, in publish File /home/bkc/Development/lib/python/Zope/__init__.py, line 221, in zpublisher_exception_hook (Object: Delivered) File /home/bkc/Development/lib/python/ZPublisher/Publish.py, line 171, in publish File /home/bkc/door2door/lib/python/ZPublisher/mapply.py, line 160, in mapply (Object: PackageInfo) File /home/bkc/Development/lib/python/ZPublisher/Publish.py, line 112, in call_object (Object: PackageInfo) File /home/bkc/Development/lib/python/OFS/DTMLDocument.py, line 189, in __call__ (Object: PackageInfo) File /home/bkc/Development/lib/python/DocumentTemplate/DT_String.py, line 540, in __call__ (Object: PackageInfo) File /home/bkc/Development/lib/python/DocumentTemplate/DT_With.py, line 151, in render (Object: GetDB().Package.TrackingNumber_index.select(trackingnumber).fetchone()) File /home/bkc/Development/lib/python/DocumentTemplate/DT_Let.py, line 149, in render (Object: shipment="GetDB().Shipment.ShipmentId_index.select(shipmentid).fetchone()") File /home/bkc/Development/lib/python/OFS/DTMLDocument.py, line 182, in __call__ (Object: PackageEventInfo) File /home/bkc/Development/lib/python/DocumentTemplate/DT_String.py, line 540, in __call__ (Object: PackageEventInfo) File /home/bkc/Development/lib/python/DocumentTemplate/DT_Let.py, line 149, in render (Object: dCache="CacheObject(('PackageEventDetailEven','PackageEventDetailOdd'))") File /home/bkc/Development/lib/python/DocumentTemplate/DT_In.py, line 701, in renderwob (Object: SQLPackageEvent) File /home/bkc/door2door/lib/python/Shared/DC/ZRDB/Results.py, line 174, in __getitem__ File /home/bkc/door2door/lib/python/Shared/DC/ZRDB/Results.py, line 157, in __init__ (Object: PackageEvent) File /home/bkc/Development/Extensions/Strader.py, line 100, in __init__ (Object: PackageEvent) AttributeError: eday
Geez. OK... I'm not sure. Can you set *any* attribute on the instance? I have no idea how this stuff works, unfortunately. ----- Original Message ----- From: "Brad Clements" <bkc@murkworks.com> To: "Chris McDonough" <chrism@digicool.com>; <zope@zope.org> Sent: Thursday, July 05, 2001 2:14 PM Subject: Re: [Zope] ZSQL Pluggable brains broke in later Zope, can't add instance attributes
On 5 Jul 2001, at 13:48, Chris McDonough wrote:
I'm actually sort of surprised that it used to work at all.. I'd imagine that AttributeError is on the eventtime attr, right?
Nope, I'm being denied the ability to put 'eday' into self.__dict__
Anyway, eventtime *is* already in self.__dict__ before the brain is created
Why doesn't self.eday= ... work? At 13:59 05/07/01 -0400, Chris McDonough wrote:
Geez. OK... I'm not sure. Can you set *any* attribute on the instance? I have no idea how this stuff works, unfortunately.
<snip>
On 5 Jul 2001, at 19:33, J. Cone wrote:
Why doesn't self.eday= ... work?
I believe this didn't work in 2.2.2, so I had to use the self.__dict__['eday']=xyz trick. I just can't seem to grock Record, Persistance and Implicit, but somehow they're playing a game there and this may be solvable with the correct __of__ I just don't know what __of__ really means! Brad Clements, bkc@murkworks.com (315)268-1000 http://www.murkworks.com (315)268-9812 Fax netmeeting: ils://ils.murkworks.com AOL-IM: BKClements
On 5 Jul 2001, at 13:59, Chris McDonough wrote:
Geez. OK... I'm not sure. Can you set *any* attribute on the instance? I have no idea how this stuff works, unfortunately.
class PackageEvent: """Package Event Pluggable Brain""" def __init__(self): """initialize""" self.eventid = 'my eventid' # this is a column in the sql resultset self.mydata = 'made up column' Even though eventid is in the resultset (therefore in the Record schema), I get an attributeError on self.eventid = 'my eventid' # this is a column in the sql resultset So .. something has changed from 2.2.2 to 2.3.3 (I didn't try any intervening version). On 2.2.2 it works.
OK, sorry, Brad, I don't have a quick answer. Do you think you can submit this to the Collector? - C ----- Original Message ----- From: "Brad Clements" <bkc@murkworks.com> To: "Chris McDonough" <chrism@digicool.com> Cc: <zope@zope.org> Sent: Thursday, July 05, 2001 2:51 PM Subject: Re: [Zope] ZSQL Pluggable brains broke in later Zope, can't add instance attributes
On 5 Jul 2001, at 13:59, Chris McDonough wrote:
Geez. OK... I'm not sure. Can you set *any* attribute on the instance? I have no idea how this stuff works, unfortunately.
class PackageEvent: """Package Event Pluggable Brain""" def __init__(self): """initialize""" self.eventid = 'my eventid' # this is a column in the sql resultset self.mydata = 'made up column'
Even though eventid is in the resultset (therefore in the Record schema), I get an attributeError on
self.eventid = 'my eventid' # this is a column in the sql resultset
So .. something has changed from 2.2.2 to 2.3.3 (I didn't try any intervening version).
On 2.2.2 it works.
participants (3)
-
Brad Clements -
Chris McDonough -
J. Cone