[storm] Error when setting a ref
James Henstridge
james at jamesh.id.au
Tue Jul 29 03:41:43 BST 2008
On Mon, Jul 28, 2008 at 5:02 PM, Gabriel Rossetti
<gabriel.rossetti at arimaz.com> wrote:
> Hello everyone,
>
> I have been debugging a test program but I don't see where the error is
> comming from. I get this :
>
[snip]
> Traceback (most recent call last):
[snip]
> 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")
^^ Here you define groupId to be a Unicode column referencing the
UserGroup table.
>
> 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")
^^^ but here you define the key for the UserGroup table to be an
integer. When you try to assign to the reference, Storm finds that
the types are incompatible.
James.
More information about the storm
mailing list