Use Case
========
The cron run perfectly well when there is no concurrent transaction.
But in real life users may interact with leads modified in the cron.
This cause two issue:
Concurrent update
-----------------
If a lead is modified in another transaction during a the transaction
where the lead is modified. The parameter crm.assignment.commit.bundle
allow to reduce the size of the transaction but before this commit
the first transaction was always way longer because it took the time
to handle the bundle + the fetching of all the data at the begining of
the cron.
The solution: start a new transaction after the preparation
of the data is done
Missing record
--------------
If the a lead is deleted in another transaction before
the transaction that modified the lead starts.
The code will then try to access a record which does not
exist anymore in the database causing a Cache Miss and Missing record
error.
The solution: Make sure a record exists in the current transaction
before using it. It reduce a little bit the performance of the cron
but avoiding the crashes is at this price.
Discussion
----------
This commit does not remove completely the risk of crash
due to concurrent update but reduce its probability a lot.
To remove the risk of crash, a proper exception management should be
implement in a further commit
closesodoo/odoo#74166
X-original-commit: 4a70f7539ec53b9c3419f83d584ad99111d2e172
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>