[Twisted-web] A problem with convertToData in nevow.accessors

Russell Duhon twisted-web@twistedmatrix.com
Fri, 26 Mar 2004 09:16:52 -0600


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I created a quick workaround by just checking if data is a list and if  
so returning it before the IGettable call.

Its a hack, but it works well enough for now as all my Deferred db  
calls for data will return lists.


On Mar 25, 2004, at 10:11 PM, Russell Duhon wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> I'm starting work on an app and ran into an odd little problem, and  
> while in general I'd love to hack around on nevow to figure out  
> exactly where its arising I need to go to sleep now, and would like to  
> be able to progress on my project come tomorrow.
>
> Basically, I've got a data function that returns a Deferred (from the  
> adbapi dbpool's runQuery method)-- that seems to get handled just fine  
> - -- which is used for a sequence rendering.  However, in the function  
> convertToData in accessors.py, an error occurs:
>
> (nevow is just checked out from CVS, twisted is checked out from CVS a  
> few days ago.  I did install Nevow in site-packages, but I don't think  
> that would be causing this).
>
> 2004/03/25 21:57 CST [-] FAILURE ! [Failure instance: Traceback:  
> exceptions.AttributeError, ListContainer instance has no attribute  
> 'get'
> 2004/03/25 21:57 CST [-]  
> /System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
> python2.3/site-packages/twisted/internet/defer.py:338:_runCallbacks
> 2004/03/25 21:57 CST [-]  
> /System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
> python2.3/site-packages/nevow/accessors.py:15:convertToData
>
> After educating myself somewhat on interfaces, I changed the code to  
> help me debug the issue:
>
> def convertToData(data, context):
>     from twisted.python import log
>     log.err('data: ' + str(data))
>     log.err('data type: ' + str(type(data)))
>     newdata = IGettable(data, persist=False, default=None)
>     log.err('newdata: ' + str(newdata))
>     if newdata is not None:
>         newdata = newdata.get(context)
>         if isinstance(newdata, Deferred):
>             return newdata.addCallback(convertToData, context)
>         else:
>             return convertToData(newdata, context)
>     else:
>         return data
>
> (original function was:
>
> def convertToData(data, context):
>     newdata = IGettable(data, persist=False, default=None)
>     if newdata is not None:
>         newdata = newdata.get(context)
>         if isinstance(newdata, Deferred):
>             return newdata.addCallback(convertToData, context)
>         else:
>             return convertToData(newdata, context)
>     else:
>         return data
> )
>
> Well, that produced some semi-mystifying results:
>
> 2004/03/25 21:57 CST [-] "data: [['samson and delilah', 'delilah and  
> frank']]"
> 2004/03/25 21:57 CST [-] "data type: <type 'list'>"
> 2004/03/25 21:57 CST [-] 'newdata: <nevow.accessors.ListContainer  
> instance at 0x111d968>'
> 2004/03/25 21:57 CST [-] FAILURE ! [Failure instance: Traceback:  
> exceptions.AttributeError, ListContainer instance has no attribute  
> 'get'
> 2004/03/25 21:57 CST [-]  
> /System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
> python2.3/site-packages/twisted/internet/defer.py:338:_runCallbacks
> 2004/03/25 21:57 CST [-]  
> /System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
> python2.3/site-packages/nevow/accessors.py:19:convertToData
>
> My guess is that IGettable is in this case supposed to return the None  
> of the default argument, and thus the list itself be returned, but I'm  
> not absolutely certain of that, and if that is what's supposed to  
> happen, I'm in the dark as to why its not happening, and would need to  
> peruse how Nevow handles interfaces a fair amount more, I think.
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.4 (Darwin)
>
> iD8DBQFAY61qFZO4LxR6+NgRAnE5AJ0TrpTFHOqJ/jP2yjAiz8pbpSgg2gCfXYtz
> uqLcFj09SklpstYAKdRNZh4=
> =yIwf
> -----END PGP SIGNATURE-----
>
>
> _______________________________________________
> Twisted-web mailing list
> Twisted-web@twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)

iD8DBQFAZEllFZO4LxR6+NgRAg9PAJ9+BJKdiD3JoUDVWaxYXh6+tEidVQCeIzLj
d8YJo7erIGXP9nz70kgVLfU=
=5W1S
-----END PGP SIGNATURE-----