uuid-doctrine icon indicating copy to clipboard operation
uuid-doctrine copied to clipboard

Fetching association throws "Unknown parameter type, 116 given" exception

Open delolmo opened this issue 2 years ago • 6 comments

Tbh, I am not 100% sure that this issue lies within this library, within doctrine/orm or within doctrine/dbal. Having said that, let me share my findings on what is happening to me.

The project in question is based on doctrine/orm, which is being tested locally with the pdo_sqlite library. I have two very basic entities with the following mapping:

#[ORM\Entity]
#[ORM\Table(name: 'accounts')]
#[ORM\InheritanceType('SINGLE_TABLE')]
#[ORM\DiscriminatorColumn(name: 'type', type: 'string')]
#[ORM\DiscriminatorMap([
    'organization' => Organization::class,
    'user' => User::class,
])]
abstract class Account
{
    public function __construct(
        #[ORM\Id]
        #[ORM\Column(type: 'uuid_binary')]
        private UuidInterface $id,
        #[ORM\Column(type: 'string', unique: true)]
        private string $name,
        #[ORM\Column(type: 'string', unique: true)]
        private string $email,
        #[ORM\Column(type: 'string', enumType: Level::class)]
        private Level $level,
        #[ORM\Column(type: 'datetime_immutable')]
        private DateTimeImmutable $createdAt,
    ) {
    }
#[ORM\Entity]
class User extends Account
{
}
#[ORM\Entity]
class Organization extends Account
{
}

Plus an association class with the following definition:

#[ORM\Entity]
#[ORM\Table(name: 'accounts_members')]
#[ORM\UniqueConstraint(columns: ['organization_id', 'user_id'])]
class Member
{
    final public function __construct(
        #[ORM\Id]
        #[ORM\Column(type: 'uuid_binary')]
        private UuidInterface $id,
        #[ORM\ManyToOne(targetEntity: Organization::class, fetch: 'EAGER')]
        #[ORM\JoinColumn(name: 'organization_id', referencedColumnName: 'id')]
        private Organization $organization,
        #[ORM\ManyToOne(targetEntity: User::class, fetch: 'EAGER')]
        #[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id')]
        private User $user,
        #[ORM\Column(type: 'string', enumType: Role::class)]
        private Role $role,
    ) {
    }
}

I believe the entities are self-explanatory, but I will be happy to provide more context if necessary.

That being said, I am running this code inside the controller:

        $entityManager = $this->getEntityManager();

        $repo = $entityManager->getRepository(Member::class);

        $all = $repo->findAll();

After which I am getting the following Exception:

In ExceptionConverter.php line 83:
                                                                                     
  [Doctrine\DBAL\Exception\DriverException]                                          
  An exception occurred while executing a query: Unknown parameter type, 116 given.  
                                                                                     

Exception trace:
  at /.web/model/vendor/doctrine/dbal/src/Driver/API/SQLite/ExceptionConverter.php:83
 Doctrine\DBAL\Driver\API\SQLite\ExceptionConverter->convert() at /.web/model/vendor/doctrine/dbal/src/Connection.php:1907
 Doctrine\DBAL\Connection->handleDriverException() at /.web/model/vendor/doctrine/dbal/src/Connection.php:1850
 Doctrine\DBAL\Connection->convertExceptionDuringQuery() at /.web/model/vendor/doctrine/dbal/src/Connection.php:1069
 Doctrine\DBAL\Connection->executeQuery() at /.web/model/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php:916
 Doctrine\ORM\Persisters\Entity\BasicEntityPersister->loadAll() at /.web/model/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:3015
 Doctrine\ORM\UnitOfWork->triggerEagerLoads() at /.web/model/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php:68
 Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator->hydrateAllData() at /.web/model/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php:270
 Doctrine\ORM\Internal\Hydration\AbstractHydrator->hydrateAll() at /.web/model/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php:920
 Doctrine\ORM\Persisters\Entity\BasicEntityPersister->loadAll() at /.web/model/vendor/doctrine/orm/lib/Doctrine/ORM/EntityRepository.php:225
 Doctrine\ORM\EntityRepository->findBy() at /.web/model/vendor/doctrine/orm/lib/Doctrine/ORM/EntityRepository.php:207
 Doctrine\ORM\EntityRepository->findAll() at /.web/model/src/Handler/ListMembers.php:19
 App\Handler\ListMembers->__invoke() at /.web/model/src/Console/Command/ListMembers.php:27
 App\Controller\ListMembers->execute() at /.web/model/vendor/symfony/console/Command/Command.php:312
 Symfony\Component\Console\Command\Command->run() at /.web/model/vendor/symfony/console/Application.php:1022
 Symfony\Component\Console\Application->doRunCommand() at /.web/model/vendor/symfony/console/Application.php:314
 Symfony\Component\Console\Application->doRun() at /.web/model/vendor/symfony/console/Application.php:168
 Symfony\Component\Console\Application->run() at /.web/model/bin/console:34

After some investigation into the issue, I found out that the misterious unknown parameter 116 is 'created' here:

Doctrine\ORM\Persisters\Entity\BasicEntityPersister->loadAll()

Which eventually calls this (the actual line where the 116 is 'added'):

https://github.com/doctrine/orm/blob/2.14.x/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php#L1962

Does anyone have any idea why I am getting this error?

Locked versions of the libraries are:

  • doctrine/orm, 2.14.1
  • ramsey/uuid-doctrine, 2.0.0
  • ramsey/uuid, 4.7.3

delolmo avatar Jan 23 '23 17:01 delolmo

I have actually revisited this and it is in fact a bug in the library. Changing every primary key from 'uuid_binary' type to 'uuid' made everything work fine again.

delolmo avatar Jan 26 '23 14:01 delolmo

I had the same issue with v2.x. Rolling back to v1 helped. Didn't notice anything in the CHANGELOG.md

sakalys avatar Apr 24 '23 10:04 sakalys

Same here with:

ramsey/uuid: 4.7.4
ramsey/uuid-doctrine: 2.0.0
doctrine/orm: 2.15.2

acelot avatar Jun 20 '23 11:06 acelot

It seems it's a bug on ORM side https://github.com/doctrine/orm/issues/7835 TLDR; findBy doesn't accept non-builtin array types

Helped rewriting findBy calls by query builder.

acelot avatar Jun 20 '23 12:06 acelot

@acelot Can you provide more details on what you mean by "helped rewriting findBy calls by query builder?"

ramsey avatar Jun 26 '23 19:06 ramsey

FYI as its not mentined here. Error "Unknown parameter type, 116 given" is caused by https://github.com/ramsey/uuid-doctrine/pull/72 (released in 2.0.0) and already fixed upstream in PR https://github.com/doctrine/dbal/pull/5994 . ArrayParametrType does not support BINARY type right now. After applying patch from PR everything is working as expected.

vitkutny avatar Jul 11 '23 21:07 vitkutny