Skip to content

Fix TypeError in EnqueueRelatedIdsHandler when element was deleted before message consumption#431

Open
cancan101 wants to merge 1 commit into
pimcore:2026.xfrom
cancan101:fix/enqueue-related-ids-deleted-element
Open

Fix TypeError in EnqueueRelatedIdsHandler when element was deleted before message consumption#431
cancan101 wants to merge 1 commit into
pimcore:2026.xfrom
cancan101:fix/enqueue-related-ids-deleted-element

Conversation

@cancan101

Copy link
Copy Markdown
Contributor

Changes in this pull request

EnqueueRelatedIdsMessage carries only an element ID. If the element is deleted between the dispatch of the message (e.g. from updateIndexQueue(..., enqueueRelatedItemsAsync: true) on element save) and its consumption by a messenger worker, ElementService::getElementByType() returns null. Passing that to IndexQueueService::updateIndexQueue() throws:

TypeError: Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexQueueService::updateIndexQueue(): Argument #1 ($element) must be of type Pimcore\Model\Element\ElementInterface, null given, called in .../src/MessageHandler/EnqueueRelatedIdsHandler.php on line 48

Since a TypeError is an Error (and is raised at argument binding), the try/catch (Exception) inside updateIndexQueue() cannot catch it, so the message lands in the failed transport where retries can never succeed — the element is gone.

This PR skips processing when the element no longer exists, and adds a unit test covering the regression. There is nothing left to enqueue related items for in that case; the deletion of the element itself is handled separately via the DELETE queue operation.

Additional info

Observed in production on v2.5.2 under a save-then-delete race (transient objects from import jobs). The same guard already exists conceptually in other ID-based async flows where the element is re-loaded from an ID.

🤖 Generated with Claude Code

EnqueueRelatedIdsMessage carries only an element ID. If the element is
deleted between the dispatch of the message and its consumption by a
messenger worker, ElementService::getElementByType() returns null and
passing it to IndexQueueService::updateIndexQueue() throws a TypeError,
sending the message to the failed transport where retries can never
succeed.

Skip processing in that case, mirroring the null handling of the other
ID-based message handlers.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EnqueueRelatedIdsHandler crashes with TypeError when element is deleted between dispatch and handle

2 participants