[albatross-users] Python 2.4.1 incompatibility with al-for ?

Andrew McNamara andrewm at object-craft.com.au
Tue Apr 19 20:22:12 EST 2005


>I get the error when I add this line to the file:
>
><al-for iter="entry" expr="_loglist" pagesize="50" prepare />
>
>the _loglist variable is defined as the result of a MySQL query
>
>
>
>c = QA.cursor()
>result = c.execute("""SELECT changelog
>                      FROM qadb
>                      WHERE CID=%s;""" % ctx.locals._account_num)
>if result:
>    ctx.locals._loglist = c.fetchone()['changelog']
>
>Note that c is a dictionary class cursor from MySQLdb and so it returns a 
>tuple of dictionary mappings. In this case there is only one key in the 
>dictionary. I don't think that is relevant to this issue, though...
>
>It seems that there is some incompatibility with the <al-for prepare /> 
>statement shown above and Python 2.4.1

I'm using Python 2.4.1 with Albatross in complex database dependent apps
without trouble. Maybe the mysql library was upgraded when you went
from 2.2 to 2.4? My guess would be that it's returning an iterable,
rather than an array. Currently <al-for> requires an indexable object
such as an array or tuple. I guess you could try something like:

    c = QA.cursor()
    result = c.execute("""SELECT changelog
                          FROM qadb
                          WHERE CID=%s;""" % ctx.locals._account_num)
    if result:
        _loglist = c.fetchone()['changelog']
        for i in range(len(_loglist)):
            print _loglist[i]

This essentially duplicates what Albatross does internally when accessing
the supplied object.

-- 
Andrew McNamara, Senior Developer, Object Craft
http://www.object-craft.com.au/



More information about the Albatross-users mailing list