Review main Merged

96830[BUGFIX] Avoid duplicate MM rows when copying both relation sides

Benni Mack CR +2 V +2 Normal +106 −1 updated 10/23/26, 08:58

Commit message

When a page is copied that contains both sides of a bidirectional
MM relation (MM_opposite_field), the record copied first writes a
relation to the original of the other side. The record copied
afterwards picks up this relation as well, so remapping turns both
the original and the copy into the same uid. writeMM() then inserts
the relation twice, which nowadays fails with a unique constraint
violation and aborts the copy.

Remapping now drops such a stale item if the copy it maps to is
already part of the relation, and updates the relation count of
the record accordingly.

Review

  • Code review CR +2 Done
    • Benni Mack +2
    • Oli Bartsch +1
  • Verified V +2 Done
    • Benni Mack +2
    • Oli Bartsch +1
    • core-ci +1 CI

Issues 2

Files 4

Review log 79

  1. Benni Mack uploaded patch set 1 10/18/26, 16:17

  2. core-ci voted on patch set 1 V +1 10/18/26, 16:28 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/111542

  3. Benni Mack marked it ready for review 10/23/26, 06:36

  4. Oli Bartsch commented on patch set 1 10/23/26, 08:20

    I ran into the same issue via #109847 and pushed https://review.typo3.org/c/Packages/TYPO3.CMS/+/96966, which fixes it in the same method. Yours is older and covers the older issue, so I'll abandon mine in favour of this one. One difference between the two approaches is described inline; apart from that, the result is the same for the reported case.

    DataHandler.php:7040

    This drops the item for every MM field, including fields with "multiple" enabled. For those, DefaultTcaSchema creates the MM table with its own uid primary key (see the "multiple" handling around line 1122), so repeated relations are allowed and no unique constraint violation can occur. If a record is intentionally related to both the original and the copy, this would silently remove a relation. Limiting it to fields without "multiple" would keep the fix to the case that actually breaks: ```php if (!empty($conf['MM']) && !($conf['multiple'] ?? false) && isset($existingItems[$v['table'] . ':' . $mapID])) { ```
  5. Oli Bartsch uploaded patch set 2 V +1 10/23/26, 08:29

  6. Oli Bartsch commented on patch set 2 CR +1 V +1 10/23/26, 08:30

    Reply

    Done

    DataHandler.php:7040 Reply

    Done
  7. core-ci voted on patch set 2 V +1 10/23/26, 08:58 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/112245

  8. Benni Mack voted on patch set 2 CR +2 V +2 10/23/26, 08:58

  9. Benni Mack merged patch set 3 10/23/26, 08:58