[storm] Error when setting a ref : SOLVED, stupid error on my part...

Gabriel Rossetti gabriel.rossetti at arimaz.com
Mon Jul 28 10:26:10 BST 2008


Gabriel Rossetti wrote:
> Hello everyone,
>
> I have been debugging a test program but I don't see where the error is 
> comming from. I get this :
>
> INSERT INTO user_group (name) VALUES (%s) (u'admin',)
> SELECT user_group.user_group_id FROM user_group WHERE 
> user_group.user_group_id = 5 ()
> INSERT INTO user_group (name) VALUES (%s) (u'users',)
> SELECT user_group.user_group_id FROM user_group WHERE 
> user_group.user_group_id = 6 ()
> INSERT INTO `language` (name) VALUES (%s) (u'ENGLISH',)
> SELECT `language`.language_id FROM `language` WHERE 
> `language`.language_id = 5 ()
> INSERT INTO `language` (name) VALUES (%s) (u'FRENCH',)
> SELECT `language`.language_id FROM `language` WHERE 
> `language`.language_id = 6 ()
> Traceback (most recent call last):
>   File 
> "/home/gr/Documents/Code/Python/Proj1/src/services/common/orm.py", line 
> 974, in <module>
>     orm.populateDb(store)
>   File 
> "/home/gr/Documents/Code/Python/Proj1/src/services/common/orm.py", line 
> 772, in populateDb
>     user1 = User(u"Toto", u"Titi", group1, lang1)
>   File 
> "/home/gr/Documents/Code/Python/Proj1/src/services/common/orm.py", line 
> 140, in __init__
>     self.group = group
>   File "/usr/lib/python2.5/site-packages/storm/references.py", line 147, 
> in __set__
>     self._relation.link(local, remote, True)
>   File "/usr/lib/python2.5/site-packages/storm/references.py", line 567, 
> in link
>     local_vars[local_column].set(remote_var.get())
>   File "/usr/lib/python2.5/site-packages/storm/variables.py", line 192, 
> in set
>     new_value = self.parse_set(value, from_db)
>   File "/usr/lib/python2.5/site-packages/storm/variables.py", line 372, 
> in parse_set
>     % (type(value), value))
> TypeError: Expected unicode, found <type 'int'>: 5
>
> What I don't get is that the code doesn't do anything strange, it does 
> stuff like it's done in the tutorial :
>
> class User(Storm):
>     __storm_table__ = "user"
>    
>     id = Int(primary=True, name="user_id")
>     firstName = Unicode(name="first_name")
>     lastName = Unicode(name="last_name")
>     languageId = Int(name="language_id")
>     language = Reference(languageId, "Language.id")
>     userParams = ReferenceSet(id, "UserParam.id")
>     groupId = Unicode(name="user_group_id")
>     group = Reference(groupId, "UserGroup.id")
>    
>     def __init__(self, firstName, lastName, group, lang):
>         self.firstName = firstName
>         self.lastName = lastName
>         self.group = group  # <-- this is where the exception is raised
>         self.language = lang
>
> class Language(Storm):
>     __storm_table__ = "language"
>    
>     id = Int(primary=True, name="language_id")
>     name = Unicode()
>    
>     def __init__(self, name):
>         self.name = name
>
> class UserGroup(Storm):
>     __storm_table__ = "user_group"
>    
>     id = Int(primary=True, name="user_group_id")
>     name = Unicode()
>    
>     def __init__(self, name):
>         self.name = name
>
> def populateDb(store):
>     # Create the test groups
>     group1 = UserGroup(u"admin")
>     print str(group1)
>     store.add(group1)
>     group2 = UserGroup(u"users")
>     store.add(group2)
>     store.flush()
>    
>     # Create the test languages
>     lang1 = Language(u"ENGLISH")
>     store.add(lang1)
>     lang2 = Language(u"FRENCH")
>     store.add(lang2)
>     store.flush()
>    
>     # Create the test users
>     print str(group1) + ", " + str(lang1)
>     user1 = User(u"Toto", u"Titi", group1, lang1) <-- this is where the 
> exception is raised
>     store.add(user1)
>     store.flush()
>    
>     # ...
>
>
> I don't get it, any ideas?
> Gabriel
>
>   
I'm sorry guys, I just saw my error, I must be blind, I re-read this 
code multiple times, and the error said it all.....

Gabriel



More information about the storm mailing list