Argument 1 passed to KeyValuePair must be of the type string, int given

When trying to handle media via the admin api I came across the next exception:
[Argument 1 passed to Shopware\Core\Framework\DataAbstractionLayer\Write\DataStack\KeyValuePair::__construct() must be of the type string, int given]

If I take a look at the file where the KeyValuePair class is called i see the next code:

foreach ($originalData as $key => $value) {
    $this->data[$key] = new KeyValuePair($key, $value, true);
}

In addition to the fact that the class is deprecated it asks for a string $key in the constructor:

class KeyValuePair
{
    /**
     * @var string
     */
    private $key;

    private $value;

    /**
     * @var bool
     */
    private $isRaw;

    public function __construct(string $key, $value, bool $isRaw)
    {
        $this->key = $key;
        $this->value = $value;
        $this->isRaw = $isRaw;
    }

    public function getKey(): string
    {
        return $this->key;
    }

    public function getValue()
    {
        return $this->value;
    }

    public function isRaw(): bool
    {
        return $this->isRaw;
    }

    public function setValue($value): void
    {
        $this->isRaw = false;
        $this->value = $value;
    }
}

Does someone knows how to fix this or how to make sure this deprecated class is not used anymore?

Have you checked what your IDs look like? Are your IDs all numbers? Then that could be the problem.

I had that problem too. but the error occurred via the storefront.
The problem for me was that the IDs only consisted of numbers and this was converted to an int in between. And in the end the error you described occurred.

I had this fixed this afternoon, but now I stumble across the same issue but this time from the shopware migration assistent. This struck me as odd, because I did not touched that code at all. I don’t even decide what data is been send.

{"errors":[{"code":"0","status":"500","title":"Internal Server Error","detail":"SwagMigrationAssistant\\Migration\\Premapping\\PremappingChoiceStruct::__construct(): Argument #1 ($uuid) must be of type string, int given

Have you found the solution to Argument #1 ($uuid) must be of type string, int given? Having same problem.

Thanks

@p.potharlanka , are you getting the error through the storefront? Say you have a numeric ID and want to do something with it?

Are you accessing the ID with DomAccess.getDataAttribute? Then probably here’s the problem. Because getDataAttribute parses the ID to an int.
Attempt to access the attribute differently.

Hey thanks for the reply. The error was due to the PHP version which i was using after downgrading to V 8.0, it has resolved.