sonata-project / SonataAdminBundle

The missing Symfony Admin Generator
https://docs.sonata-project.org/projects/SonataAdminBundle
MIT License
2.11k stars 1.26k forks source link

SQLSTATE[HY093]: Invalid parameter number: parameter was not defined when using doctrine_orm_choice #5535

Closed Aerendir closed 4 years ago

Aerendir commented 5 years ago

Environment

MacOS macOS 10.14.1

Sonata packages

$ composer show --latest 'sonata-project/*'
sonata-project/admin-bundle              3.48.1 3.48.1 The missing Symfony Admin Generator
sonata-project/block-bundle              3.15.0 3.15.0 Symfony SonataBlockBundle
sonata-project/cache                     2.0.1  2.0.1  Cache library
sonata-project/core-bundle               3.16.2 3.16.2 Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.5.0  3.0.0  Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.2.0  1.2.0  Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.9.0  3.9.0  Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/exporter                  2.0.1  2.0.1  Lightweight Exporter library

Symfony packages

$ composer show --latest 'symfony/*'
symfony/apache-pack          v1.0.1  v1.0.1  A pack for Apache support in Symfony
symfony/asset                v4.2.7  v4.2.7  Symfony Asset Component
symfony/cache                v4.2.7  v4.2.7  Symfony Cache component with PSR-6, PSR-16, and tags
symfony/config               v4.2.7  v4.2.7  Symfony Config Component
symfony/console              v4.2.7  v4.2.7  Symfony Console Component
symfony/contracts            v1.0.2  v1.0.2  A set of abstractions extracted out of the Symfony components
symfony/css-selector         v4.2.7  v4.2.7  Symfony CssSelector Component
symfony/debug                v4.2.7  v4.2.7  Symfony Debug Component
symfony/dependency-injection v4.2.7  v4.2.7  Symfony DependencyInjection Component
symfony/doctrine-bridge      v4.2.7  v4.2.7  Symfony Doctrine Bridge
symfony/dom-crawler          v4.2.7  v4.2.7  Symfony DomCrawler Component
symfony/dotenv               v4.2.7  v4.2.7  Registers environment variables from a .env file
symfony/event-dispatcher     v4.2.7  v4.2.7  Symfony EventDispatcher Component
symfony/expression-language  v4.2.7  v4.2.7  Symfony ExpressionLanguage Component
symfony/filesystem           v4.2.7  v4.2.7  Symfony Filesystem Component
symfony/finder               v4.2.7  v4.2.7  Symfony Finder Component
symfony/flex                 v1.2.3  v1.2.3  Composer plugin for Symfony
symfony/form                 v4.2.7  v4.2.7  Symfony Form Component
symfony/framework-bundle     v4.2.7  v4.2.7  Symfony FrameworkBundle
symfony/http-foundation      v4.2.7  v4.2.7  Symfony HttpFoundation Component
symfony/http-kernel          v4.2.7  v4.2.7  Symfony HttpKernel Component
symfony/inflector            v4.2.7  v4.2.7  Symfony Inflector Component
symfony/intl                 v4.2.7  v4.2.7  A PHP replacement layer for the C intl extension that includes additional data from the ICU library.
symfony/monolog-bridge       v4.2.7  v4.2.7  Symfony Monolog Bridge
symfony/monolog-bundle       v3.3.1  v3.3.1  Symfony MonologBundle
symfony/options-resolver     v4.2.7  v4.2.7  Symfony OptionsResolver Component
symfony/orm-pack             v1.0.6  v1.0.6  A pack for the Doctrine ORM
symfony/phpunit-bridge       v4.2.7  v4.2.7  Symfony PHPUnit Bridge
symfony/polyfill-ctype       v1.11.0 v1.11.0 Symfony polyfill for ctype functions
symfony/polyfill-intl-icu    v1.11.0 v1.11.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-intl-idn    v1.11.0 v1.11.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-mbstring    v1.11.0 v1.11.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php72       v1.11.0 v1.11.0 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/process              v4.2.7  v4.2.7  Symfony Process Component
symfony/profiler-pack        v1.0.4  v1.0.4  A pack for the Symfony web profiler
symfony/property-access      v4.2.7  v4.2.7  Symfony PropertyAccess Component
symfony/property-info        v4.2.7  v4.2.7  Symfony Property Info Component
symfony/routing              v4.2.7  v4.2.7  Symfony Routing Component
symfony/security-acl         v3.0.2  v3.0.2  Symfony Security Component - ACL (Access Control List)
symfony/security-bundle      v4.2.7  v4.2.7  Symfony SecurityBundle
symfony/security-core        v4.2.7  v4.2.7  Symfony Security Component - Core Library
symfony/security-csrf        v4.2.7  v4.2.7  Symfony Security Component - CSRF Library
symfony/security-guard       v4.2.7  v4.2.7  Symfony Security Component - Guard
symfony/security-http        v4.2.7  v4.2.7  Symfony Security Component - HTTP Integration
symfony/serializer           v4.2.7  v4.2.7  Symfony Serializer Component
symfony/stopwatch            v4.2.7  v4.2.7  Symfony Stopwatch Component
symfony/swiftmailer-bundle   v3.2.6  v3.2.6  Symfony SwiftmailerBundle
symfony/templating           v4.2.7  v4.2.7  Symfony Templating Component
symfony/translation          v4.2.7  v4.2.7  Symfony Translation Component
symfony/twig-bridge          v4.2.7  v4.2.7  Symfony Twig Bridge
symfony/twig-bundle          v4.2.7  v4.2.7  Symfony TwigBundle
symfony/validator            v4.2.7  v4.2.7  Symfony Validator Component
symfony/var-dumper           v4.2.7  v4.2.7  Symfony mechanism for exploring and dumping PHP variables
symfony/var-exporter         v4.2.7  v4.2.7  A blend of var_export() + serialize() to turn any serializable data structure to plain PHP code
symfony/web-profiler-bundle  v4.2.7  v4.2.7  Symfony WebProfilerBundle
symfony/web-server-bundle    v4.2.7  v4.2.7  Symfony WebServerBundle
symfony/webpack-encore-pack  v1.0.3  v1.0.3  A pack for Symfony Encore
symfony/workflow             v4.2.7  v4.2.7  Symfony Workflow Component
symfony/yaml                 v4.2.7  v4.2.7  Symfony Yaml Component

PHP version

$ php -v
PHP 7.2.9 (cli) (built: Aug 21 2018 07:42:00) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.9, Copyright (c) 1999-2018, by Zend Technologies
    with Xdebug v2.6.1, Copyright (c) 2002-2018, by Derick Rethans

Subject

I'm trying to configure a filter with a dropdown where I list some possible statuses for an entity.

The dropdown is built correctly, but when I click on "Filter" I receive the following error:

An exception occurred while executing 'SELECT count(DISTINCT q0_.id) AS sclr_0 FROM queues_scheduledjobs q0 WHERE q0_.status IN (?, ?)' with params [null, "new"]:

SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

Steps to reproduce

Install the bundle:

composer req serendipity_hq/commands-queues-bundle:dev-feature/sonata-admin
  1. Open vendor/serendipity_hq/commands-queues-bundle/src/Admin/Sonata/Entity/JobAdmin
  2. Uncomment the lines in the method JobAdmin::configureDatagridFilters() (and comment the one line that creates the filter without dropdown)
  3. Then go to the administration managed by SonataAdmin: the bundle will auto-configure itself
  4. Try to filter the jobs
  5. Click on "Filter"
  6. The error throws

Expected results

All the jobs with the selected status are shown.

Actual results

An exception occurred while executing 'SELECT count(DISTINCT q0_.id) AS sclr_0 FROM queues_scheduledjobs q0 WHERE q0_.status IN (?, ?)' with params [null, "new"]:

SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

The stacktrace is this:

[3/3] DriverException

Doctrine\DBAL\Exception\DriverException:
An exception occurred while executing 'SELECT count(DISTINCT q0_.id) AS sclr_0 FROM queues_scheduled_jobs q0_ WHERE q0_.status IN (?, ?)' with params [null, "new"]:

SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

  at vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:106
  at Doctrine\DBAL\Driver\AbstractMySQLDriver->convertException('An exception occurred while executing \'SELECT count(DISTINCT q0_.id) AS sclr_0 FROM queues_scheduled_jobs q0_ WHERE q0_.status IN (?, ?)\' with params [null, "new"]:SQLSTATE[HY093]: Invalid parameter number: parameter was not defined', object(PDOException))
     (vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:169)
  at Doctrine\DBAL\DBALException::wrapException(object(Driver), object(PDOException), 'An exception occurred while executing \'SELECT count(DISTINCT q0_.id) AS sclr_0 FROM queues_scheduled_jobs q0_ WHERE q0_.status IN (?, ?)\' with params [null, "new"]:SQLSTATE[HY093]: Invalid parameter number: parameter was not defined')
     (vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:145)
  at Doctrine\DBAL\DBALException::driverExceptionDuringQuery(object(Driver), object(PDOException), 'SELECT count(DISTINCT q0_.id) AS sclr_0 FROM queues_scheduled_jobs q0_ WHERE q0_.status IN (?, ?)', array('type' => null, 'value' => 'new'))
     (vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:911)
  at Doctrine\DBAL\Connection->executeQuery('SELECT count(DISTINCT q0_.id) AS sclr_0 FROM queues_scheduled_jobs q0_ WHERE q0_.status IN (?, ?)', array('type' => null, 'value' => 'new'), array(2, 2), null)
     (vendor/doctrine/orm/lib/Doctrine/ORM/Query/Exec/SingleSelectExecutor.php:50)
  at Doctrine\ORM\Query\Exec\SingleSelectExecutor->execute(object(Connection), array(array('type' => null, 'value' => 'new')), array(102))
     (vendor/doctrine/orm/lib/Doctrine/ORM/Query.php:334)
  at Doctrine\ORM\Query->_doExecute()
     (vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:967)
  at Doctrine\ORM\AbstractQuery->executeIgnoreQueryCache(null, 4)
     (vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:922)
  at Doctrine\ORM\AbstractQuery->execute(null, 4)
     (vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:803)
  at Doctrine\ORM\AbstractQuery->getSingleResult(4)
     (vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:831)
  at Doctrine\ORM\AbstractQuery->getSingleScalarResult()
     (vendor/sonata-project/doctrine-orm-admin-bundle/src/Datagrid/Pager.php:48)
  at Sonata\DoctrineORMAdminBundle\Datagrid\Pager->computeNbResult()
     (vendor/sonata-project/doctrine-orm-admin-bundle/src/Datagrid/Pager.php:65)
  at Sonata\DoctrineORMAdminBundle\Datagrid\Pager->init()
     (vendor/sonata-project/admin-bundle/src/Datagrid/Datagrid.php:182)
  at Sonata\AdminBundle\Datagrid\Datagrid->buildPager()
     (vendor/sonata-project/admin-bundle/src/Datagrid/Datagrid.php:265)
  at Sonata\AdminBundle\Datagrid\Datagrid->getForm()
     (vendor/sonata-project/admin-bundle/src/Controller/CRUDController.php:169)
  at Sonata\AdminBundle\Controller\CRUDController->listAction()
     (vendor/symfony/http-kernel/HttpKernel.php:150)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor/symfony/http-kernel/HttpKernel.php:67)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor/symfony/http-kernel/Kernel.php:198)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (public/index.php:32)

[2/3] PDOException

Doctrine\DBAL\Driver\PDOException:
SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

  at vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:119
  at Doctrine\DBAL\Driver\PDOStatement->execute()
     (vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:903)
  at Doctrine\DBAL\Connection->executeQuery('SELECT count(DISTINCT q0_.id) AS sclr_0 FROM queues_scheduled_jobs q0_ WHERE q0_.status IN (?, ?)', array('type' => null, 'value' => 'new'), array(2, 2), null)
     (vendor/doctrine/orm/lib/Doctrine/ORM/Query/Exec/SingleSelectExecutor.php:50)
  at Doctrine\ORM\Query\Exec\SingleSelectExecutor->execute(object(Connection), array(array('type' => null, 'value' => 'new')), array(102))
     (vendor/doctrine/orm/lib/Doctrine/ORM/Query.php:334)
  at Doctrine\ORM\Query->_doExecute()
     (vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:967)
  at Doctrine\ORM\AbstractQuery->executeIgnoreQueryCache(null, 4)
     (vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:922)
  at Doctrine\ORM\AbstractQuery->execute(null, 4)
     (vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:803)
  at Doctrine\ORM\AbstractQuery->getSingleResult(4)
     (vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:831)
  at Doctrine\ORM\AbstractQuery->getSingleScalarResult()
     (vendor/sonata-project/doctrine-orm-admin-bundle/src/Datagrid/Pager.php:48)
  at Sonata\DoctrineORMAdminBundle\Datagrid\Pager->computeNbResult()
     (vendor/sonata-project/doctrine-orm-admin-bundle/src/Datagrid/Pager.php:65)
  at Sonata\DoctrineORMAdminBundle\Datagrid\Pager->init()
     (vendor/sonata-project/admin-bundle/src/Datagrid/Datagrid.php:182)
  at Sonata\AdminBundle\Datagrid\Datagrid->buildPager()
     (vendor/sonata-project/admin-bundle/src/Datagrid/Datagrid.php:265)
  at Sonata\AdminBundle\Datagrid\Datagrid->getForm()
     (vendor/sonata-project/admin-bundle/src/Controller/CRUDController.php:169)
  at Sonata\AdminBundle\Controller\CRUDController->listAction()
     (vendor/symfony/http-kernel/HttpKernel.php:150)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor/symfony/http-kernel/HttpKernel.php:67)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor/symfony/http-kernel/Kernel.php:198)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (public/index.php:32)

[1/3] PDOException

PDOException:
SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

  at vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:117
  at PDOStatement->execute(null)
     (vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:117)
  at Doctrine\DBAL\Driver\PDOStatement->execute()
     (vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:903)
  at Doctrine\DBAL\Connection->executeQuery('SELECT count(DISTINCT q0_.id) AS sclr_0 FROM queues_scheduled_jobs q0_ WHERE q0_.status IN (?, ?)', array('type' => null, 'value' => 'new'), array(2, 2), null)
     (vendor/doctrine/orm/lib/Doctrine/ORM/Query/Exec/SingleSelectExecutor.php:50)
  at Doctrine\ORM\Query\Exec\SingleSelectExecutor->execute(object(Connection), array(array('type' => null, 'value' => 'new')), array(102))
     (vendor/doctrine/orm/lib/Doctrine/ORM/Query.php:334)
  at Doctrine\ORM\Query->_doExecute()
     (vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:967)
  at Doctrine\ORM\AbstractQuery->executeIgnoreQueryCache(null, 4)
     (vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:922)
  at Doctrine\ORM\AbstractQuery->execute(null, 4)
     (vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:803)
  at Doctrine\ORM\AbstractQuery->getSingleResult(4)
     (vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:831)
  at Doctrine\ORM\AbstractQuery->getSingleScalarResult()
     (vendor/sonata-project/doctrine-orm-admin-bundle/src/Datagrid/Pager.php:48)
  at Sonata\DoctrineORMAdminBundle\Datagrid\Pager->computeNbResult()
     (vendor/sonata-project/doctrine-orm-admin-bundle/src/Datagrid/Pager.php:65)
  at Sonata\DoctrineORMAdminBundle\Datagrid\Pager->init()
     (vendor/sonata-project/admin-bundle/src/Datagrid/Datagrid.php:182)
  at Sonata\AdminBundle\Datagrid\Datagrid->buildPager()
     (vendor/sonata-project/admin-bundle/src/Datagrid/Datagrid.php:265)
  at Sonata\AdminBundle\Datagrid\Datagrid->getForm()
     (vendor/sonata-project/admin-bundle/src/Controller/CRUDController.php:169)
  at Sonata\AdminBundle\Controller\CRUDController->listAction()
     (vendor/symfony/http-kernel/HttpKernel.php:150)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor/symfony/http-kernel/HttpKernel.php:67)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor/symfony/http-kernel/Kernel.php:198)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (public/index.php:32)

I have no idea of how to fix this, nor if it is a fault of mine or really a bug: any ideas?

The code I'm using is this:

<?php

declare(strict_types=1);

/*
 * This file is part of the SHQCommandsQueuesBundle.
 *
 * Copyright Adamo Aerendir Crespi 2017.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @author    Adamo Aerendir Crespi <hello@aerendir.me>
 * @copyright Copyright (C) 2017 Aerendir. All rights reserved.
 * @license   MIT License.
 */

namespace SerendipityHQ\Bundle\CommandsQueuesBundle\Admin\Sonata\Entity;

use SerendipityHQ\Bundle\CommandsQueuesBundle\Entity\Daemon;
use SerendipityHQ\Bundle\CommandsQueuesBundle\Entity\Job;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\Type\Filter\ChoiceType;
use Sonata\AdminBundle\Route\RouteCollection;
use Sonata\DoctrineORMAdminBundle\Filter\ChoiceFilter;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;

/**
 * {@inheritdoc}
 */
class JobAdmin extends AbstractAdmin
{
    ....

    /**
     * {@inheritDoc}
     */
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
    {
        //$datagridMapper->add('status');

        $datagridMapper->add('status', 'doctrine_orm_choice',[], ChoiceType::class, [
            'operator_type' => HiddenType::class,
            'field_options' => [
                'choices' => [
                    'New' => Job::STATUS_NEW,
                    'Aborted' => Job::STATUS_ABORTED,
                ]
            ],
        ]);

    }

    ...
sercul commented 5 years ago

I have same error...

Aerendir commented 5 years ago

@sercul , unfortunately I was not able to solve it :(

github-actions[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.