doctrine / orm

Doctrine Object Relational Mapper (ORM)
https://www.doctrine-project.org/projects/orm.html
MIT License
9.95k stars 2.52k forks source link

Doctrine\DBAL\Driver\Exception\UnknownParameterType: Unknown parameter type, 105 given. #10691

Open brian-n-millar opened 1 year ago

brian-n-millar commented 1 year ago

Bug Report

Q A
Version DBAL 3.6.2, ORM 2.14.3

Summary

When using findBy method I am using an array of values to check for which previously worked but now gives this error.

The code is basically as follows (I've altered it a bit for posting here):

$er = $this->em->getRepository('User\Entity\User');
$collection = $er->findBy(['state' => 0, 'deleted' => [null, 0]], ['firstname' => 'ASC']);

The issue comes from deleted column, it is a boolean type in the DB, here I want to check if it is either NULL or 0 (false in MySQL). This did work fine previously, now I am getting the error in the title. I traced it through and traced down to this in file doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php in function getTypes on line 1960:

if (is_array($value)) {
    return array_map(static function ($type) {
        $type = Type::getType($type);

        return $type->getBindingType() + Connection::ARRAY_PARAM_OFFSET;
    }, $types);
}

It checks if the value is an array which it is, then gets the type of the column with is Boolean which resolves to integer 5 then adds this ARRAY_PARAM_OFFSET which adds integer 100 to the value resulting in 105 as the parameter type whereas others resolve to a string like "integer". This leads to the failure as later code doesn't understand this 105 type.

Am I doing something wrong? Is this way of using an array in a findBy deprecated or something?

derrabus commented 1 year ago

Thanks for this thorough analysis. To me, this looks like the issue is on the ORM's side, so we should transfer the issue there. Can you tell us which ORM version you're using?

brian-n-millar commented 1 year ago

doctrine/orm 2.14.3 and I'm using doctrine-orm-module 5.3.0 with Laminas

brian-n-millar commented 1 year ago

Any update?

derrabus commented 1 year ago

Not from my side. Feel free to work on a fix.

Quiesss commented 1 year ago

up

bystro commented 1 year ago
Q A
Version DBAL 3.7.2, ORM 2.17.1

I think I have the same issue when switch to EAGER fetch mode for a ManytoOne relation * @ORM\ManyToOne(targetEntity="App\Area\Entity\Area", fetch="EAGER") or $qb->getQuery()->setFetchMode(Place::class, "area", ClassMetadataInfo::FETCH_EAGER)

[Doctrine\DBAL\Exception\DriverException] An exception occurred while executing a query: Unknown parameter type, 105 given. doctrine/dbal/src/Driver/API/MySQL/ExceptionConverter.php:117


In ExceptionConverter.php line 117:

[Doctrine\DBAL\Exception\DriverException]
An exception occurred while executing a query: Unknown parameter type, 105 given.

Exception trace: at /var/www/html/modern-content-parser/vendor/doctrine/dbal/src/Driver/API/MySQL/ExceptionConverter.php:117 Doctrine\DBAL\Driver\API\MySQL\ExceptionConverter->convert() at /var/www/html/modern-content-parser/vendor/doctrine/dbal/src/Connection.php:1938 Doctrine\DBAL\Connection->handleDriverException() at /var/www/html/modern-content-parser/vendor/doctrine/dbal/src/Connection.php:1880 Doctrine\DBAL\Connection->convertExceptionDuringQuery() at /var/www/html/modern-content-parser/vendor/doctrine/dbal/src/Connection.php:1105 Doctrine\DBAL\Connection->executeQuery() at /var/www/html/modern-content-parser/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php:939 Doctrine\ORM\Persisters\Entity\BasicEntityPersister->loadAll() at /var/www/html/modern-content-parser/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:3147 Doctrine\ORM\UnitOfWork->triggerEagerLoads() at /var/www/html/modern-content-parser/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php:126 Doctrine\ORM\Internal\Hydration\ObjectHydrator->cleanup() at /var/www/html/modern-content-parser/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php:272 Doctrine\ORM\Internal\Hydration\AbstractHydrator->hydrateAll() at /var/www/html/modern-content-parser/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:1225 Doctrine\ORM\AbstractQuery->executeIgnoreQueryCache() at /var/www/html/modern-content-parser/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:1166 Doctrine\ORM\AbstractQuery->execute() at /var/www/html/modern-content-parser/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:991

In UnknownParameterType.php line 21:

[Doctrine\DBAL\Driver\Exception\UnknownParameterType]
Unknown parameter type, 105 given.

Exception trace: at /var/www/html/modern-content-parser/vendor/doctrine/dbal/src/Driver/Exception/UnknownParameterType.php:21 Doctrine\DBAL\Driver\Exception\UnknownParameterType::new() at /var/www/html/modern-content-parser/vendor/doctrine/dbal/src/Driver/PDO/ParameterTypeMap.php:36 Doctrine\DBAL\Driver\PDO\ParameterTypeMap::convertParamType() at /var/www/html/modern-content-parser/vendor/doctrine/dbal/src/Driver/PDO/Statement.php:45 Doctrine\DBAL\Driver\PDO\Statement->bindValue() at /var/www/html/modern-content-parser/vendor/doctrine/dbal/src/Connection.php:1804 Doctrine\DBAL\Connection->bindParameters() at /var/www/html/modern-content-parser/vendor/doctrine/dbal/src/Connection.php:1096 Doctrine\DBAL\Connection->executeQuery() at /var/www/html/modern-content-parser/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php:939 Doctrine\ORM\Persisters\Entity\BasicEntityPersister->loadAll() at /var/www/html/modern-content-parser/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:3147 Doctrine\ORM\UnitOfWork->triggerEagerLoads() at /var/www/html/modern-content-parser/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php:126 Doctrine\ORM\Internal\Hydration\ObjectHydrator->cleanup() at /var/www/html/modern-content-parser/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php:272 Doctrine\ORM\Internal\Hydration\AbstractHydrator->hydrateAll() at /var/www/html/modern-content-parser/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:1225 Doctrine\ORM\AbstractQuery->executeIgnoreQueryCache() at /var/www/html/modern-content-parser/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:1166 Doctrine\ORM\AbstractQuery->execute() at /var/www/html/modern-content-parser/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:991

derrabus commented 1 year ago

Do you want to investigate the issue or work on a fix? If not, a reproducer or even a full stack trace would be helpful for anyone who wants to contribute a fix.

bystro commented 1 year ago

The issue was with a boolean type on PRIMARY KEY. It works when changed to integer

* @ORM\Column(name="id", type="integer", nullable=false)

derrabus commented 1 year ago

@derrabus why do you keep hoping a community member will just come along and fix this? Why is it not taken seriously by Doctrine team?

Since you're addressing me directly, I will try to answer your questions as politely as I'm able to.

The short answer is: The bug does neither affects me personally nor anyone who pays me for my work. Believe it or not, my day only has 24 hours like everyone else's. I have a day job and a family. So, my personal priorities are (in that order):

This is a bug affecting production systems with detailed evidence shown by 2 users now and originally reported months ago.

Nobody's disputing the the existence of this bug.

I understand you are probably volunteers

Now, do you.

I appreciate the work open source devs do for free

Really.

but it doesn't inspire confidence in people/companies to use your project in production when they have a problem and your response is basically 'fix it yourself'.

Then, don't use it. Write and maintain your own ORM. Please. I have no intention to fix stuff for some freeloaders that complain about me not aligning my priorities with theirs.


So, if anyone wants to help getting this bug fixed, I'm happy to provide all the support I can.