ERROR: could not serialize access due to concurrent update ( ir.session )

Dear tryton team,
I’m trying to post and invoice from flask_tryton, but when I call subprocess postgresql gives me always this error on psql log.

ERROR: could not serialize access due to concurrent update
STATEMENT: UPDATE “ir_session” SET “write_uid” = 0, “write_date” = CURRENT_TIMESTAMP WHERE ((“ir_session”.“id” IN (197)))
… repeat x times

I know I’m missing something, as I’m passing pool instance to external module to make the post, maybe it’s because of that?.

Thanks if somebody knew what could be the error. btw, on second attempt works :expressionless:
https://pastebin.com/ufUtFUuN

Ok, I think I know what could be the issue:
https://pastebin.com/vKDX10xJ
In the above paste the exception raise on Invoice.set_number(invoices), Invoice for my it’s a pool instance of account_invoice, in tryton it’s cls. the class, but I’m not sure why works on second attempt. :neutral_face:

Exception when resetting the session, may happen in case of high concurrency. This should not be a problem.
By the way normally it is only a debug log: trytond: 5d3eafccb4d1 trytond/security.py

I’m looking forward , because I’m using only one user and only one post at time . My subprocces.call returns ok , but the exception is raised on flask.
I’ll look more and check if I can find the issue cause I’m no able to post invoice , (by the way the sp.call just make a webservice call validation of invoice data).

Thanks for your time !

That’s because the subprocess creates another transaction which updates the same record and this causes your error.

If you want to do some processing in background you should enable worker service and Tryton will manage the async process for you.

Except if you are waiting for the result. In this case, you would need Issue 8318: Parallelism tasks - Tryton issue tracker

@pokoli was right , my subprocess call did an update transaction on same account invoice table. What I did to solve the issue was call two times the subprocess (on different routes , so different @tryton.transactions ) the first one to make the update and trigger the validation , the second to consult the status of previous validation and then post if validation were ok .

Thanks all