Create triggers are not executed when user is 0

(Sergi Almacellas Abellana) #1

I’m developing a flask application connected to tryton. One of the requirements is to send some mail notification when a new record is created. In order to send this notifications we used the notification_email module in order to setup the templating.

But my surprise is that triggers are skipped when user is root (0), which is the case for web applications.

I’m wondering if there is some special reason for skipping triggers. For me they should be triggered for all users on the system.

(Cédric Krier) #2

They are skipped for root because it is the user of the migration/update. We do not want to trigger business logic during this process.
I think it is not a good idea to use root for normal processes.

(Sergi Almacellas Abellana) #3

So when using flask_tryton to create a web frontend do you recomend to create a specific user for all the requests?

(Cédric Krier) #4

Yes probably (until now we have always used ‘admin’).

(Sergi Almacellas Abellana) #5

If somebody comes across the same issue here is the code we used to set the user:

ModelData = tryton.pool.get('')                                                                                                           
def get_user():                                                                
     with Transaction().start(app.config['TRYTON_DATABASE'], 0):                
         return ModelData.get_id('module', 'xml_id')         
app.config['TRYTON_USER'] = get_user()