mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Wrong commit order in some relation cases #5857
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @contentrail on GitHub (Jan 24, 2018).
Issue was found after updating to v.2.6 and associated with improvements in CommitOrderCalculator class.
Here is the example to reproduce.
Objects:
Book has optional relation to the PCT object. Some Bookes has PCT and some not. But all PCT has relation to Book.
How to reproduce:
Find one Book (or create new).
Create new PCT object with even one PCTFee object for this Book object.
Try to flush.
Error:
I've try to figure out why and found that CommitOrderCalculator produce wrong commit order: PCTFee, Book, PCT.
It's wrong because PCTFee depends on PCT - PCT must be saved earlier.
New code in CommitOrderCalculator uses weights of relations. But weights is wrong.
We have 2 relations with different weights (nullable and not nullable):
Before version 2.6 CommitOrderCalculator has checked both relations. But now it checks only relation with maximum weight!
I've removed code using weights from CommitOrderCalculator:
and bug has disappeared.