Thank you, that clarifies things for me. On Thursday, 30 July 2015 11:09:07 UTC-4, Anthony wrote: > > Same answer. Each request is handled in a separate thread, so any code in > a model, controller, or view is run in a fresh environment. When you define > a table or specify callbacks in a model file, it's like it is happening for > the first time (as it only applies to the current request) -- it is not as > if a new copy of your callback function is being appended to an > ever-growing list on every request. You would only be appending the same > function twice if your code includes: > > db.tt._after_update.append(myfunc) > > in two separate places. > > Anthony > > On Thursday, July 30, 2015 at 11:01:51 AM UTC-4, Thomas Sitter wrote: >> >> Sorry I should have clarified my question. >> >> The part I'm concerned about is the use of *append* when adding the >> callback. If append is being used is there any check to make sure a >> function is not already in the list. I do not want to call the same >> callback multiple times when a record is updated. >> >> In the sourcecode _after_callback is implemented as a list and I see no >> checks to make sure the same function isn't inserted/called more than once. >> Perhaps it should be a set? >> >> >> >> On Thursday, 30 July 2015 00:50:49 UTC-4, Anthony wrote: >>> >>> auth.add_group() actually does a database insert, so you don't want to >>> keep repeating it on every request (actually, I would probably move that >>> code out of the app altogether, as it really only needs to be run once >>> ever). >>> >>> Specifying the after update callback, on the other hand, does not affect >>> the database at all -- it simply tells the DAL what to do after a database >>> update. In fact, you need this to run on every request because it is part >>> of the model definition (for the same reason you need to run the associated >>> db.define_table() on every request). >>> >>> Anthony >>> >>> On Wednesday, July 29, 2015 at 10:59:59 PM UTC-4, Thomas Sitter wrote: >>>> >>>> Hello, >>>> >>>> I'm adding an _after_update callback to my table in db.py using: >>>> >>>> def myfunc(s,f): >>>> #do stuff >>>> return False >>>> >>>> db.tt._after_update.append(myfunc) >>>> >>>> My question is whether this will continuously append this method every >>>> time a database table is modified. >>>> >>>> I'm asking because I had a similar issue when creating the initial auth >>>> users/groups in db.py. I had to wrap the code in the following logic to >>>> prevent them being added multiple times >>>> >>>> if not db().select(db.auth_user.ALL).first(): >>>> group_1 = auth.add_group('group1', 'group1 employees') >>>> ... >>>> >>>> >>>> Thanks >>>> >>>
-- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.