sonata-project / SonataDoctrineMongoDBAdminBundle

Symfony Sonata / Integrate Doctrine MongoDB ODM into the SonataAdminBundle
https://docs.sonata-project.org/projects/SonataDoctrineMongoDBAdminBundle
MIT License
65 stars 95 forks source link

Cant delete documents from list view => ProxyQuery::setFirstResult and ProxyQuery::setMaxResults doesn't support null #370

Closed edguar closed 4 years ago

edguar commented 4 years ago

Environment

Sonata packages

$ composer show --latest 'sonata-project/*'
sonata-project/admin-bundle                  3.66.0 3.66.0 The missing Symfony Admin Generator
sonata-project/block-bundle                  3.18.5 4.2.0  Symfony SonataBlockBundle
sonata-project/cache                         2.0.1  2.0.1  Cache library
sonata-project/core-bundle                   3.19.0 3.19.0 Symfony SonataCoreBundle (abandoned)
sonata-project/doctrine-extensions           1.6.0  1.6.0  Doctrine2 behavioral extensions
sonata-project/doctrine-mongodb-admin-bundle 3.3.0  3.3.0  Symfony Sonata / Integrate Doctrine MongoDB ODM into the SonataAdminBundle
sonata-project/exporter                      2.2.0  2.2.0  Lightweight Exporter library

Symfony packages

$ composer show --latest 'symfony/*'
symfony/asset                      v4.4.8  v4.4.8  Symfony Asset Component
symfony/cache                      v4.4.8  v4.4.8  Symfony Cache component with PSR-6, PSR-16, and tags
symfony/cache-contracts            v2.0.1  v2.0.1  Generic abstractions related to caching
symfony/config                     v4.4.8  v4.4.8  Symfony Config Component
symfony/console                    v4.4.8  v4.4.8  Symfony Console Component
symfony/css-selector               v4.4.8  v4.4.8  Symfony CssSelector Component
symfony/debug                      v4.4.8  v4.4.8  Symfony Debug Component
symfony/dependency-injection       v4.4.8  v4.4.8  Symfony DependencyInjection Component
symfony/doctrine-bridge            v4.4.8  v4.4.8  Symfony Doctrine Bridge
symfony/dotenv                     v4.4.8  v4.4.8  Registers environment variables from a .env file
symfony/error-handler              v4.4.8  v4.4.8  Symfony ErrorHandler Component
symfony/event-dispatcher           v4.4.8  v4.4.8  Symfony EventDispatcher Component
symfony/event-dispatcher-contracts v1.1.7  v2.0.1  Generic abstractions related to dispatching event
symfony/expression-language        v4.4.8  v4.4.8  Symfony ExpressionLanguage Component
symfony/filesystem                 v4.4.8  v4.4.8  Symfony Filesystem Component
symfony/finder                     v4.4.8  v4.4.8  Symfony Finder Component
symfony/flex                       v1.7.0  v1.7.0  Composer plugin for Symfony
symfony/form                       v4.4.8  v4.4.8  Symfony Form Component
symfony/framework-bundle           v4.4.8  v4.4.8  Symfony FrameworkBundle
symfony/http-foundation            v4.4.8  v4.4.8  Symfony HttpFoundation Component
symfony/http-kernel                v4.4.8  v4.4.8  Symfony HttpKernel Component
symfony/inflector                  v4.4.8  v4.4.8  Symfony Inflector Component
symfony/intl                       v4.4.8  v4.4.8  A PHP replacement layer for the C intl extension that includes additional data from the ICU library.
symfony/mailer                     v4.4.8  v4.4.8  Symfony Mailer Component
symfony/messenger                  v4.4.8  v4.4.8  Symfony Messenger Component
symfony/mime                       v4.4.8  v4.4.8  A library to manipulate MIME messages
symfony/options-resolver           v4.4.8  v4.4.8  Symfony OptionsResolver Component
symfony/polyfill-intl-grapheme     v1.17.0 v1.17.0 Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-icu          v1.17.0 v1.17.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-intl-idn          v1.17.0 v1.17.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer   v1.17.0 v1.17.0 Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring          v1.17.0 v1.17.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php72             v1.17.0 v1.17.0 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-php73             v1.17.0 v1.17.0 Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions
symfony/profiler-pack              v1.0.4  v1.0.4  A pack for the Symfony web profiler
symfony/property-access            v4.4.8  v4.4.8  Symfony PropertyAccess Component
symfony/routing                    v4.4.8  v4.4.8  Symfony Routing Component
symfony/security-acl               v3.0.4  v3.0.4  Symfony Security Component - ACL (Access Control List)
symfony/security-bundle            v4.4.8  v4.4.8  Symfony SecurityBundle
symfony/security-core              v4.4.8  v4.4.8  Symfony Security Component - Core Library
symfony/security-csrf              v4.4.8  v4.4.8  Symfony Security Component - CSRF Library
symfony/security-guard             v4.4.8  v4.4.8  Symfony Security Component - Guard
symfony/security-http              v4.4.8  v4.4.8  Symfony Security Component - HTTP Integration
symfony/service-contracts          v2.0.1  v2.0.1  Generic abstractions related to writing services
symfony/stopwatch                  v4.4.8  v4.4.8  Symfony Stopwatch Component
symfony/string                     v5.0.8  v5.0.8  Symfony String component
symfony/templating                 v4.4.8  v4.4.8  Symfony Templating Component
symfony/translation                v4.4.8  v4.4.8  Symfony Translation Component
symfony/translation-contracts      v2.0.1  v2.0.1  Generic abstractions related to translation
symfony/twig-bridge                v4.4.8  v4.4.8  Symfony Twig Bridge
symfony/twig-bundle                v4.4.8  v4.4.8  Symfony TwigBundle
symfony/twig-pack                  v1.0.0  v1.0.0  A Twig pack for Symfony projects
symfony/validator                  v4.4.8  v4.4.8  Symfony Validator Component
symfony/var-dumper                 v4.4.8  v4.4.8  Symfony mechanism for exploring and dumping PHP variables
symfony/var-exporter               v4.4.8  v4.4.8  A blend of var_export() + serialize() to turn any serializable data structure to plain PHP code
symfony/web-profiler-bundle        v4.4.8  v4.4.8  Symfony WebProfilerBundle
symfony/webpack-encore-bundle      v1.7.3  v1.7.3  Integration with your Symfony app & Webpack Encore!
symfony/yaml                       v4.4.8  v4.4.8  Symfony Yaml Component

PHP version

$ php -v
PHP 7.3.17 (cli) (built: Apr 14 2020 12:23:51) ( ZTS MSVC15 (Visual C++ 2017) x64 )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.17, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.17, Copyright (c) 1999-2018, by Zend Technologies

Subject

I try to delete documents from list view (batch action). After confirmation get error

Actual results

TypeError:
Argument 1 passed to Doctrine\ODM\MongoDB\Query\Builder::skip() must be of the type int, null given, called in D:\OSPanel\domains\symfony\portal2-4.4\vendor\sonata-project\doctrine-mongodb-admin-bundle\src\Datagrid\ProxyQuery.php on line 97

  at D:\OSPanel\domains\symfony\portal2-4.4\vendor\doctrine\mongodb-odm\lib\Doctrine\ODM\MongoDB\Query\Builder.php:1415
  at Doctrine\ODM\MongoDB\Query\Builder->skip(null)
     (D:\OSPanel\domains\symfony\portal2-4.4\vendor\sonata-project\doctrine-mongodb-admin-bundle\src\Datagrid\ProxyQuery.php:97)
  at Sonata\DoctrineMongoDBAdminBundle\Datagrid\ProxyQuery->setFirstResult(null)
     (D:\OSPanel\domains\symfony\portal2-4.4\vendor\sonata-project\admin-bundle\src\Controller\CRUDController.php:510)
  at Sonata\AdminBundle\Controller\CRUDController->batchAction()
     (D:\OSPanel\domains\symfony\portal2-4.4\vendor\symfony\http-kernel\HttpKernel.php:158)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (D:\OSPanel\domains\symfony\portal2-4.4\vendor\symfony\http-kernel\HttpKernel.php:80)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (D:\OSPanel\domains\symfony\portal2-4.4\vendor\symfony\http-kernel\Kernel.php:201)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request), 1, true)
     (D:\OSPanel\domains\symfony\portal2-4.4\vendor\symfony\http-kernel\HttpCache\SubRequestHandler.php:85)
  at Symfony\Component\HttpKernel\HttpCache\SubRequestHandler::handle(object(Kernel), object(Request), 1, true)
     (D:\OSPanel\domains\symfony\portal2-4.4\vendor\symfony\http-kernel\HttpCache\HttpCache.php:477)
  at Symfony\Component\HttpKernel\HttpCache\HttpCache->forward(object(Request), true, null)
     (D:\OSPanel\domains\symfony\portal2-4.4\vendor\symfony\framework-bundle\HttpCache\HttpCache.php:62)
  at Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache->forward(object(Request), true)
     (D:\OSPanel\domains\symfony\portal2-4.4\vendor\symfony\http-kernel\HttpCache\HttpCache.php:267)
  at Symfony\Component\HttpKernel\HttpCache\HttpCache->pass(object(Request), true)
     (D:\OSPanel\domains\symfony\portal2-4.4\vendor\symfony\http-kernel\HttpCache\HttpCache.php:283)
  at Symfony\Component\HttpKernel\HttpCache\HttpCache->invalidate(object(Request), true)
     (D:\OSPanel\domains\symfony\portal2-4.4\vendor\symfony\http-kernel\HttpCache\HttpCache.php:211)
  at Symfony\Component\HttpKernel\HttpCache\HttpCache->handle(object(Request))
     (D:\OSPanel\domains\symfony\portal2-4.4\public\index.php:35)

Working if change null to 0 https://github.com/sonata-project/SonataAdminBundle/blob/9b1c68a906afc10f48d41476375e658920d59f1b/src/Controller/CRUDController.php#L510-L511

VincentLanglet commented 4 years ago

Hi @edguar, this is a https://github.com/sonata-project/SonataDoctrineMongoDBAdminBundle issue.

null is supposed to be a valid value. The ProxyQuery methods should be fixed.

The following calls are invalid.

$this->queryBuilder->skip(null);
$this->queryBuilder->limit(null);

But I don't know how they should be fixed.

I understand limit(0) as 0 result, when limit(null) was meant to be no limit so every result.

Do you know @edguar ? Do you want to try a PR ?

Maybe a PR should be open to doctrine/mongodb-odm ?

@franmomu Maybe do you know ?

franmomu commented 4 years ago

I think setting both to 0 would be the same as null, I'll check later today.