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
|