Skip to content

Attempted to call function "is_mixed" from the global namespace for "symfony/doctrine-messenger" package #58225

Closed as not planned
@e-repo

Description

@e-repo

Symfony version(s) affected

7.1.1

Description

I may have missed something, but I encountered a problem when trying to call the is_mixed function from the global scope while using the symfony/doctrine-messenger package.

This error occurs when attempting to execute the following commands:
messenger:consume failed
messenger:failed:retry

The issue arises because the TransportMessageIdStamp object cannot be constructed from the "X-Message-Stamp-Symfony\Component\Messenger\Stamp\TransportMessageIdStamp" header during the execution of Symfony\Component\Serializer\Serializer::deserialize(...).

The root cause is the mixed type of the id in TransportMessageIdStamp.

abstract class AbstractObjectNormalizer extends AbstractNormalizer
{
    ...
    if (('is_'.$typeIdentifier->value)($data)) {
        return $data;
    }
    ...
}

The TransportMessageIdStamp looks like this:

final class TransportMessageIdStamp implements StampInterface
{
    public function __construct(
        private mixed $id,
    ) {
    }

    public function getId(): mixed
    {
        return $this->id;
    }
}

How to reproduce

To reproduce this issue, follow these steps:

  1. Send a message to the "failure_transport" in any way while it hasn't appeared in the database via symfony/doctrine-messenger.
  2. Run messenger:failed:retry or messenger:consume failed, preferably retry, followed by writing the message back to the database (simulating an unresolved issue in the handler).
  3. During this process, the attempt to create TransportMessageIdStamp from X-Message-Stamp-Symfony\Component\Messenger\Stamp\TransportMessageIdStamp fails with an error.

Possible Solution

It might make sense to specify a more precise type in TransportMessageIdStamp, possibly using a union type.

For example:

final class TransportMessageIdStamp implements StampInterface
{
    public function __construct(
        private int|string $id,
    ) {
    }

    public function getId(): mixed
    {
        return $this->id;
    }
}

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions