Hello,
I am discovering sqlobject with turbogears and I face a problem which may be 
sum up  as follow :

My model :
(...)
class Page(SQLObject):
    pagename = UnicodeCol(alternateID=True,unique=True,notNone=True,length=15)
    tabname = UnicodeCol(length=30)
    content = RelatedJoin("Content")
    sidebar = ForeignKey("Sidebar")
(...)

And in a console:
>>> p = Page.get(1)
>>> p
<Page 1 pagename=u'home' tabname=u'home foo' sidebarID=None>
>>> p.sidebar = 1
>>> p
<Page 1 pagename=u'home' tabname=u'home foo' sidebarID=1>
>>> p.sidebar = '1'
>>> p
<Page 1 pagename=u'home' tabname=u'home foo' sidebarID=1>
>>> p.sidebar = u'1'
>>> p
<Page 1 pagename=u'home' tabname=u'home foo' sidebarID=None>

As I populate the table from a web form, all values come as a unicode type. I 
catch all of them as a key/pair value and modify my "p" record in a loop with 
something like setattr(p,key,value). 
My problem is that setattr(p,'sidebar',u'1') does not raise any error but 
silently gives the None value to sidebarID, which force me to an ugly and 
unsecure workaround :

if hasattr(p,key+'ID'):
     setattr(p,key+'ID',int(value))
 
This unicode problem does not affect RelatedJoin columns :
>>> p.addContent(u'2')
>>> p.content[1]
<Content 2 title=u'foobar' datetime='datetime.datetime...)' data=u'foo' 
widget=u'rst' css_id=u''>

So my question are : did I miss something ? Is this a bug ? Does on of you has 
a clue on how to fix this ?
Btw, I use sqlobject 0.7.1

cheers,
Luc

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to