Monday, November 5, 2018
1 change · master
Resolved issues and error corrections
This fix changes the order used when updating one-to-many linked records so old entries are removed before replacement entries are added. This helps avoid database constraint errors during updates or module upgrades, improving reliability for affected operations.
Original PR description
After 12744bc81ebdaa1671a953c14ba54c637d6a9255, o2m operations are fully batched, and deletions are processed last when the operations are flushed, regardless of the order in which they were…
After 12744bc81ebdaa1671a953c14ba54c637d6a9255, o2m operations are fully batched, and deletions are processed last when the operations are flushed, regardless of the order in which they were specified by the write() or create() call. This carries a risk of violating [non-deferred] unique SQL constraints, when the operations for deleting previous lines and re-creating new ones are processed in the same batch. This patch executes the deletions before other operations during a flush, which should be safer with regard to SQL constraints. An extra constraint is added in test_performance.line to simulate this corner case, then covered by an extra unit test. Another unrelated test had to be altered to avoid violating the new constraint. A similar error can be reproduced easily by upgrading the `project` module in master, due to [the unique constraint](https://github.com/odoo/odoo/blob/ccc42f161d9554dcf8c0eb1fed0ea6ff5a4336b5/odoo/addons/base/models/ir_actions.py#L288-L289) on `ir.actions.act_window.view`, that gets violated when processing the batch write on [this o2m](https://github.com/odoo/odoo/blob/ccc42f161d9554dcf8c0eb1fed0ea6ff5a4336b5/addons/project/views/project_views.xml#L394-L396). **Note:** the new test might best be moved to `test_new_api`, though it seemed sensible to add it among the new tests introduced by 12744bc81ebdaa1671a953c14ba54c637d6a9255