[storm] Implementing auto add parent

James Henstridge james at jamesh.id.au
Fri Feb 12 15:17:19 GMT 2010


On Fri, Feb 12, 2010 at 7:20 PM, Eduardo Willians <edujurista at gmail.com> wrote:
>> That isn't what I suggested, and it doesn't look like correct Storm
>> usage (ReferenceSets should be created at the class scope rather than
>> once per instance).  Didn't changing "self.id = oper.id" to "self.oper
>> = oper" work?
>
> Once SOLVED now.
>
> LOL :)
>
> Sorry for misunderstanding. I tried that, but I've got an "WrongStoreError":
>
> Traceback (most recent call last):
>  File "<pyshell#2>", line 1, in <module>
>    financial.add(ses)
>  File "/usr/lib/python2.6/dist-packages/storm/store.py", line 249, in add
>    raise WrongStoreError("%s is part of another store" % repr(obj))
> WrongStoreError: <share.models.financial.tables.Session object at
> 0xa59024c> is part of another store

That'd happen if you tried to add the Oper and Session objects to
different stores.

>
> So now I tried to use "ReferenceSet" (instead of "Reference") in class
> scope and then added "self.oper = oper" and it worked. Here is the
> code:
>
> <code>
>
> class Session(object):
>    __storm_table__ = "financial.session"
>    id = RawStr(primary=True)
>    initial = Float()
>    # Refs
>    oper = ReferenceSet(id, Oper.id)
>
>    def __init__(self, root, operator, initial, date_time=None,
>                 add_oper=True):
>        self.oper = Oper(root, operator, date_time, add_oper)
>        self.id = self.oper.id
>        self.initial = initial
>
> </code>
>
> Register that if I dont use "self.id = self.oper.id" I get and
> "IntegrityError" for using NULL value for id column.

Well, that's because you changed it to a ReferenceSet.  From what
you've posted so far, it sounds like you've got a one to one foreign
key relationship from Session to Oper, so using Reference was correct.

Assigning directly to a ReferenceSet like you're doing above doesn't
actually do anything useful, and raises an exception with the latest
development version of Storm.

So I'd suggest investigating why these two objects are being added to
different stores.  That sounds like a much bigger problem.

James.



More information about the storm mailing list