Skip to content

[API] Performing contact bulk edit with same contact twice triggers 500 with detached entity exception #12817

@driskell

Description

@driskell

Mautic Version

4.4.x series

PHP version

8.0.30

What browsers are you seeing the problem on?

Not relevant

What happened?

mautic.CRITICAL: Uncaught PHP Exception Doctrine\ORM\ORMInvalidArgumentException: "Detached entity Mautic\LeadBundle\Entity\Lead with ID #51245 cannot be removed"

How can we reproduce this issue?

Saw this in a queue system.

Step 1: Send a bulk contact edit API request with the same contact ID for edit twice
Step 2: Witness crash

Error stems down to BatchIdToEntityHelper being smart and being able to load an entity once and assign it twice in the returned entity map.

However, CommonApiController::processBatchForm assumes that entities appear and detaches them while processing - so if an entity appears twice - the second time round you are working on a detached entity.

Likely processBatchForm needs to update $entities if the one being detached is still in it, to replace it with the new one.

Relevant log output

No response

Code of Conduct

  • I confirm that I have read and agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    APIAnything related to the APIT2Medium difficulty to fix (issue) or test (PR)bugIssues or PR's relating to bugscontactsAnything related to contactsstaleIssues which have not received an update within 90 days

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions