sonata-project / SonataDoctrineORMAdminBundle

Integrate Doctrine ORM into the SonataAdminBundle
https://docs.sonata-project.org/projects/SonataDoctrineORMAdminBundle
MIT License
445 stars 345 forks source link

DateTimeRangeFilter "Too few parameters" exception occurs when either the 'start' or 'end' field is empty #1766

Closed tonyaxo closed 10 months ago

tonyaxo commented 12 months ago

Environment

Sonata packages

show

``` $ composer show --latest 'sonata-project/*' Direct dependencies required in composer.json: sonata-project/admin-bundle 4.14.0 4.27.1 The missing Symfony Admin Generator sonata-project/doctrine-orm-admin-bundle 4.3.3 4.13.0 Integrate Doctrine ORM into the SonataAdminBundle ```

Symfony packages

show

``` $ composer show --latest 'symfony/*' symfony/asset v6.2.7 v6.3.0 Manages URL generation and versioning of web assets such as CS... symfony/browser-kit v6.2.7 v6.3.2 Simulates the behavior of a web browser, allowing you to make ... symfony/cache v6.2.13 v6.3.5 Provides extended PSR-6, PSR-16 (and tags) implementations symfony/console v6.2.13 v6.3.4 Eases the creation of beautiful and testable command line inte... symfony/css-selector v6.2.13 v6.3.2 Converts CSS selectors to XPath expressions symfony/debug-bundle v6.2.13 v6.3.2 Provides a tight integration of the Symfony VarDumper componen... symfony/dotenv v6.2.8 v6.3.0 Registers environment variables from a .env file symfony/filesystem v6.2.12 v6.3.1 Provides basic utilities for the filesystem symfony/finder v6.2.14 v6.3.5 Finds files and directories via an intuitive fluent interface symfony/flex v2.3.2 v2.3.3 Composer plugin for Symfony symfony/form v6.2.13 v6.3.5 Allows to easily create, process and reuse HTML forms symfony/framework-bundle v6.2.13 v6.3.5 Provides a tight integration between Symfony components and th... symfony/intl v6.2.13 v6.3.2 Provides access to the localization data of the ICU library symfony/lock v6.2.12 v6.3.2 Creates and manages locks, a mechanism to provide exclusive ac... symfony/lokalise-translation-provider v6.2.8 v6.3.0 Symfony Lokalise Translation Provider Bridge symfony/mailer v6.2.12 v6.3.5 Helps sending emails symfony/maker-bundle v1.50.0 v1.51.1 Symfony Maker helps you create empty commands, controllers, fo... symfony/mime v6.2.13 v6.3.5 Allows manipulating MIME messages symfony/monolog-bundle v3.8.0 v3.8.0 Symfony MonologBundle symfony/phpunit-bridge v6.3.2 v6.3.2 Provides utilities for PHPUnit, especially user deprecation no... symfony/property-info v6.2.11 v6.3.0 Extracts information about PHP class' properties using metadat... symfony/proxy-manager-bridge v6.2.7 v6.3.0 Provides integration for ProxyManager with various Symfony com... symfony/runtime v6.2.13 v6.3.2 Enables decoupling PHP applications from global state symfony/security-bundle v6.2.13 v6.3.5 Provides a tight integration of the Security component into th... symfony/serializer v6.2.13 v6.3.5 Handles serializing and deserializing data structures, includi... symfony/translation v6.2.11 v6.3.3 Provides tools to internationalize your application symfony/twig-bundle v6.2.7 v6.3.0 Provides a tight integration of Twig into the Symfony full-sta... symfony/validator v6.3.2 v6.3.5 Provides tools to validate values symfony/web-profiler-bundle v6.2.13 v6.3.2 Provides a development tool that gives detailed information ab... symfony/workflow v6.2.13 v6.3.4 Provides tools for managing a workflow or finite state machine symfony/yaml v6.2.10 v6.3.3 Loads and dumps YAML files ```

PHP version

$ php -v
PHP 8.2.9 (cli) (built: Aug 17 2023 23:22:23) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.9, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.9, Copyright (c), by Zend Technologies
    with Xdebug v3.2.2, Copyright (c) 2002-2023, by Derick Rethans

Subject

When setting a value for only one of the fields, either start or end, DateTimeRangeFilter throws an exception:

An exception has been thrown during the rendering of a template ("Too few parameters: the query defines 2 parameters but you only bound 1").

The problem is that AbstractDateFilter::filterRange doesn't has any additional logic for DateRangeOperatorType::TYPE_NOT_BETWEEN operator https://github.com/sonata-project/SonataDoctrineORMAdminBundle/blob/4.x/src/Filter/AbstractDateFilter.php#L163

Also there is no validation for the form input.

Minimal repository with the bug

Steps to reproduce

  1. Choose filter by Period
  2. Advanced filters
  3. Select Period -> not between
  4. Set value only for field From
  5. Filter
issue

Expected results

Option 1: show the message that both fields start or end are required Option 2: change behaviour as <> Option 3:

Actual results

Exception:

An exception has been thrown during the rendering of a template ("Too few parameters: the query defines 2 parameters but you only bound 1").
VincentLanglet commented 11 months ago

On the DoctrineMongo side we're doing https://github.com/sonata-project/SonataDoctrineMongoDBAdminBundle/blob/4.x/src/Filter/AbstractDateFilter.php#L177-L183

We could do the same

Can you provide the PR @tonyaxo ?

tonyaxo commented 11 months ago

On the DoctrineMongo side we're doing https://github.com/sonata-project/SonataDoctrineMongoDBAdminBundle/blob/4.x/src/Filter/AbstractDateFilter.php#L177-L183

We could do the same

  • If just start is given, we check < $start
  • If just end is given, we check > $end

Can you provide the PR @tonyaxo ?

ok