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

Related items which are optional result in a query error #6508

Closed Martin1982 closed 3 years ago

Martin1982 commented 3 years ago

Environment

Local Symfony server php 7.3 on MacOS PHP7.4 FPM on Ubuntu Docker

Sonata packages

$ composer show --latest 'sonata-project/*'
sonata-project/admin-bundle              3.77.0 3.77.0 The missing Symfony Admin Generator
sonata-project/block-bundle              4.4.0  4.4.0  Symfony SonataBlockBundle
sonata-project/cache                     2.0.1  2.0.1  Cache library
sonata-project/doctrine-extensions       1.9.1  1.10.0 Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.24   3.24   Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/exporter                  2.4.1  2.4.1  Lightweight Exporter library
sonata-project/form-extensions           1.6.0  1.6.0  Symfony form extensions
sonata-project/twig-extensions           1.4.1  1.4.1  Sonata twig extensions

Symfony packages

$ composer show --latest 'symfony/*'
Restricting packages listed in "symfony/symfony" to "4.4.*"
symfony/amqp-messenger             v5.1.7  v5.1.7  Symfony AMQP extension Messenger Bridge
symfony/asset                      v4.4.15 v4.4.15 Symfony Asset Component
symfony/cache                      v5.1.4  v4.4.15 Symfony Cache component with PSR-6, PSR-16, and tags
symfony/cache-contracts            v2.2.0  v2.2.0  Generic abstractions related to caching
symfony/config                     v4.4.15 v4.4.15 Symfony Config Component
symfony/console                    v4.4.15 v4.4.15 Symfony Console Component
symfony/debug                      v4.4.15 v4.4.15 Symfony Debug Component
symfony/dependency-injection       v4.4.15 v4.4.15 Symfony DependencyInjection Component
symfony/deprecation-contracts      v2.2.0  v2.2.0  A generic function and convention to trigger deprecation notices
symfony/doctrine-bridge            v4.4.15 v4.4.15 Symfony Doctrine Bridge
symfony/doctrine-messenger         v5.1.7  v5.1.7  Symfony Doctrine Messenger Bridge
symfony/dotenv                     v4.4.15 v4.4.15 Registers environment variables from a .env file
symfony/error-handler              v4.4.15 v4.4.15 Symfony ErrorHandler Component
symfony/event-dispatcher           v4.4.15 v4.4.15 Symfony EventDispatcher Component
symfony/event-dispatcher-contracts v1.1.9  v2.2.0  Generic abstractions related to dispatching event
symfony/expression-language        v4.4.15 v4.4.15 Symfony ExpressionLanguage Component
symfony/filesystem                 v5.1.4  v4.4.15 Symfony Filesystem Component
symfony/finder                     v5.1.4  v4.4.15 Symfony Finder Component
symfony/flex                       v1.9.10 v1.9.10 Composer plugin for Symfony
symfony/form                       v4.4.15 v4.4.15 Symfony Form Component
symfony/framework-bundle           v4.4.15 v4.4.15 Symfony FrameworkBundle
symfony/http-client-contracts      v2.3.1  v2.3.1  Generic abstractions related to HTTP clients
symfony/http-foundation            v4.4.15 v4.4.15 Symfony HttpFoundation Component
symfony/http-kernel                v4.4.15 v4.4.15 Symfony HttpKernel Component
symfony/intl                       v5.1.4  v4.4.15 A PHP replacement layer for the C intl extension that includes additional data from the ICU library.
symfony/maker-bundle               v1.21.1 v1.21.1 Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.
symfony/messenger                  v5.1.4  v4.4.15 Symfony Messenger Component
symfony/mime                       v5.1.4  v4.4.15 A library to manipulate MIME messages
symfony/monolog-bridge             v5.1.4  v4.4.15 Symfony Monolog Bridge
symfony/monolog-bundle             v3.6.0  v3.6.0  Symfony MonologBundle
symfony/options-resolver           v5.1.4  v4.4.15 Symfony OptionsResolver Component
symfony/phpunit-bridge             v4.4.15 v5.1.7  Symfony PHPUnit Bridge
symfony/polyfill-apcu              v1.18.1 v1.18.1 Symfony polyfill backporting apcu_* functions to lower PHP versions
symfony/polyfill-intl-grapheme     v1.18.1 v1.18.1 Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-icu          v1.18.1 v1.18.1 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-intl-idn          v1.18.1 v1.18.1 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer   v1.18.1 v1.18.1 Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring          v1.18.1 v1.18.1 Symfony polyfill for the Mbstring extension
symfony/polyfill-php73             v1.18.1 v1.18.1 Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions
symfony/polyfill-php80             v1.18.1 v1.18.1 Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions
symfony/property-access            v5.1.4  v4.4.15 Symfony PropertyAccess Component
symfony/property-info              v5.1.4  v4.4.15 Symfony Property Info Component
symfony/redis-messenger            v5.1.7  v5.1.7  Symfony Redis extension Messenger Bridge
symfony/routing                    v4.4.15 v4.4.15 Symfony Routing Component
symfony/security-acl               v3.1.0  v3.1.0  Symfony Security Component - ACL (Access Control List)
symfony/security-bundle            v4.4.15 v4.4.15 Symfony SecurityBundle
symfony/security-core              v4.4.15 v4.4.15 Symfony Security Component - Core Library
symfony/security-csrf              v4.4.15 v4.4.15 Symfony Security Component - CSRF Library
symfony/security-guard             v4.4.15 v4.4.15 Symfony Security Component - Guard
symfony/security-http              v4.4.15 v4.4.15 Symfony Security Component - HTTP Integration
symfony/service-contracts          v2.2.0  v2.2.0  Generic abstractions related to writing services
symfony/string                     v5.1.7  v5.1.7  Symfony String component
symfony/swiftmailer-bundle         v3.5.1  v3.5.1  Symfony SwiftmailerBundle
symfony/templating                 v4.4.15 v4.4.15 Symfony Templating Component
symfony/translation                v4.4.15 v4.4.15 Symfony Translation Component
symfony/translation-contracts      v2.3.0  v2.3.0  Generic abstractions related to translation
symfony/twig-bridge                v4.4.15 v4.4.15 Symfony Twig Bridge
symfony/twig-bundle                v4.4.15 v4.4.15 Symfony TwigBundle
symfony/validator                  v4.4.15 v4.4.15 Symfony Validator Component
symfony/var-dumper                 v5.1.4  v4.4.15 Symfony mechanism for exploring and dumping PHP variables
symfony/var-exporter               v5.1.4  v4.4.15 A blend of var_export() + serialize() to turn any serializable data structure to plain PHP code
symfony/yaml                       v4.4.15 v4.4.15 Symfony Yaml Component

PHP version

$ php -v
PHP 7.3.11 (cli) (built: Jun  5 2020 23:50:40) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.11, Copyright (c) 1998-2018 Zend Technologies

Subject

When creating an admin class with an optional ModelType field the entity cannot be saved when leaving the field empty. I tried it on multiple fields with multiple configurations. It doesn't seem to me a query error would be the expected result.

Steps to reproduce

Create an admin field with a ModelType:

                ->add('outputChannels', ModelType::class, [
                    'multiple' => true,
                    'expanded' => true,
                ])

Expected results

The item gets saved with no item attached

Actual results

500-error;

Doctrine\ORM\Query\
QueryException
SELECT DISTINCT o.channelId FROM Martin1982\LiveBroadcastBundle\Entity\Channel\AbstractChannel o WHERE ( ) ORDER BY o.channelId ASC
VincentLanglet commented 3 years ago

HI @Martin1982, do you have a repository to reproduce the error ? It would allow us to debug this more easily

Martin1982 commented 3 years ago

I just committed a temporary fix (which is downgrading to 3.76) to my demo project so you'd have to upgrade admin-bundle to 3.77 to let the error re-occur again;

https://github.com/Martin1982/live-broadcast-demo

If you'd like to test using my project, create a twitch channel and then plan a new broadcast with no channel or input attached.

The same issue occured yesterday in our main Spinnin' Records admin on a whole different entity, but that one is a private repo.

VincentLanglet commented 3 years ago

@phansys It's related to this PR: https://github.com/sonata-project/SonataAdminBundle/pull/6315/files

The issue is that addIdentifiersToQuery is not working when called with an empty array https://github.com/sonata-project/SonataDoctrineORMAdminBundle/blob/3.x/src/Model/ModelManager.php#L504-L525

Imho we should

simplegr commented 3 years ago

Having the same problem!