In order to attach the function, I have a function which is being called 
through JSON-RPC, and looks like this:

@service.jsonrpc
def append_listeners():
   print db.comments._after_insert  # prints []
   db.comments._after_insert.append(MyFunction)
   print db.comments._after_insert  # prints [<function MyFunction at 
0xabfb8df4>]

No matter how many times I call this function, the print statements stay 
the same (except for the address of the function MyFunction).
I modified the insert function in dal.py for debugging:
    def insert(self, **fields):
        print "_after_insert array: ", self._after_insert  # prints 
_after_insert array:  []
        print "table name: ", self._tablename # prints table name: comments
        self._attempt_upload(fields)
        if any(f(fields) for f in self._before_insert): return 0
        ret =  self._db._adapter.insert(self,self._listify(fields))
        ret and [f(fields,ret) for f in self._after_insert]
        return ret

and indeed, when I insert something to the comments table, I get two lines 
printed out as shown in the comments text.
It seems that the additional function is not saved in the table object.

Am I doing something fundamentally wrong? Should I add the function from 
the model file? Or at any other place?

Thanks,
Omri



On Monday, June 11, 2012 5:33:53 PM UTC+2, Anthony wrote:
>
> I tried adding a method using:
>> def SomeMethod(fields,res):
>>     print "inside SomeMethod"
>>
>> db.my_table._after_insert.append(SomeMethod)
>>
>> but nothing seems to happen. Is it possible that the implementation of 
>> the adapters
>> does not call the methods inside _after_insert, _after_update and 
>> _after_delete?
>>
>
> I would think it should work. Have you also defined any _before_insert 
> functions -- if they return anything, the insert will be aborted? Also, are 
> you sure the insert is happening -- if not, the _after_insert functions 
> won't run. You may need to show more code.
>
> Anthony 
>

Reply via email to