Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug AdminType field: Argument 3 passed to Sonata\AdminBundle\Manipulator\ObjectManipulator::callSetter() must be of the type string, null given #6218

Closed
DExploN opened this issue Jul 22, 2020 · 5 comments · Fixed by #6219

Comments

@DExploN
Copy link

DExploN commented Jul 22, 2020

Sonata packages

$ composer show --latest 'sonata-project/*'

sonata-project/admin-bundle              3.72.0 3.72.0 The missing Symfony Admin Generator
sonata-project/block-bundle              3.20.0 3.20.0 Symfony SonataBlockBundle
sonata-project/cache                     2.0.1  2.0.1  Cache library
sonata-project/core-bundle               3.20.0 3.20.0 Symfony SonataCoreBundle (abandoned)
Package sonata-project/core-bundle is abandoned, you should avoid using it. No replacement was suggested.
sonata-project/doctrine-extensions       1.7.0  1.8.0  Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.21.0 3.21.0 Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/exporter                  2.3.0  2.3.0  Lightweight Exporter library
sonata-project/form-extensions           0.1.2  1.5.0  Symfony form extensions
sonata-project/intl-bundle               2.6.0  2.7.0  Symfony SonataIntlBundle
sonata-project/twig-extensions           0.1.1  1.3.1  Sonata twig extensions

Symfony packages

$ composer show --latest 'symfony/*'
symfony/asset                      v4.4.10 v4.4.10 Symfony Asset Component
symfony/browser-kit                v4.4.10 v4.4.10 Symfony BrowserKit Component
symfony/cache                      v4.4.10 v4.4.10 Symfony Cache component with PSR-6, PSR-16, and tags
symfony/cache-contracts            v2.1.3  v2.1.3  Generic abstractions related to caching
symfony/config                     v4.4.10 v4.4.10 Symfony Config Component
symfony/console                    v4.4.10 v4.4.10 Symfony Console Component
symfony/css-selector               v4.4.10 v4.4.10 Symfony CssSelector Component
symfony/debug                      v4.4.10 v4.4.10 Symfony Debug Component
symfony/debug-bundle               v4.4.10 v4.4.10 Symfony DebugBundle
symfony/dependency-injection       v4.4.10 v4.4.10 Symfony DependencyInjection Component
symfony/deprecation-contracts      v2.1.3  v2.1.3  A generic function and convention to trigger deprecation notices
symfony/doctrine-bridge            v4.4.10 v4.4.10 Symfony Doctrine Bridge
symfony/dom-crawler                v4.4.10 v4.4.10 Symfony DomCrawler Component
symfony/dotenv                     v4.4.10 v4.4.10 Registers environment variables from a .env file
symfony/error-handler              v4.4.10 v4.4.10 Symfony ErrorHandler Component
symfony/event-dispatcher           v4.4.10 v4.4.10 Symfony EventDispatcher Component
symfony/event-dispatcher-contracts v1.1.9  v2.1.3  Generic abstractions related to dispatching event
symfony/expression-language        v4.4.10 v4.4.10 Symfony ExpressionLanguage Component
symfony/filesystem                 v4.4.10 v4.4.10 Symfony Filesystem Component
symfony/finder                     v4.4.10 v4.4.10 Symfony Finder Component
symfony/flex                       v1.9.1  v1.9.1  Composer plugin for Symfony
symfony/form                       v4.4.10 v4.4.10 Symfony Form Component
symfony/framework-bundle           v4.4.10 v4.4.10 Symfony FrameworkBundle
symfony/http-client                v4.4.10 v4.4.10 Symfony HttpClient component
symfony/http-client-contracts      v2.1.3  v2.1.3  Generic abstractions related to HTTP clients
symfony/http-foundation            v4.4.10 v4.4.10 Symfony HttpFoundation Component
symfony/http-kernel                v4.4.10 v4.4.10 Symfony HttpKernel Component
symfony/inflector                  v4.4.10 v4.4.10 Symfony Inflector Component
symfony/intl                       v4.4.10 v4.4.10 A PHP replacement layer for the C intl extension that includes additional data from the ICU library.
symfony/mailer                     v4.4.10 v4.4.10 Symfony Mailer Component
symfony/maker-bundle               v1.20.0 v1.20.0 Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.
symfony/mime                       v4.4.10 v4.4.10 A library to manipulate MIME messages
symfony/monolog-bridge             v4.4.10 v4.4.10 Symfony Monolog Bridge
symfony/monolog-bundle             v3.5.0  v3.5.0  Symfony MonologBundle
symfony/options-resolver           v4.4.10 v4.4.10 Symfony OptionsResolver Component
symfony/phpunit-bridge             v4.4.10 v5.1.2  Symfony PHPUnit Bridge
symfony/polyfill-apcu              v1.18.0 v1.18.0 Symfony polyfill backporting apcu_* functions to lower PHP versions
symfony/polyfill-intl-grapheme     v1.18.0 v1.18.0 Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-icu          v1.18.0 v1.18.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-intl-idn          v1.18.0 v1.18.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer   v1.18.0 v1.18.0 Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring          v1.18.0 v1.18.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php72             v1.18.0 v1.18.0 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-php73             v1.18.0 v1.18.0 Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions
symfony/polyfill-php80             v1.18.0 v1.18.0 Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions
symfony/process                    v4.4.10 v4.4.10 Symfony Process Component
symfony/property-access            v4.4.10 v4.4.10 Symfony PropertyAccess Component
symfony/property-info              v4.4.10 v4.4.10 Symfony Property Info Component
symfony/routing                    v4.4.10 v4.4.10 Symfony Routing Component
symfony/security-acl               v3.0.4  v3.0.4  Symfony Security Component - ACL (Access Control List)
symfony/security-bundle            v4.4.10 v4.4.10 Symfony SecurityBundle
symfony/security-core              v4.4.10 v4.4.10 Symfony Security Component - Core Library
symfony/security-csrf              v4.4.10 v4.4.10 Symfony Security Component - CSRF Library
symfony/security-guard             v4.4.10 v4.4.10 Symfony Security Component - Guard
symfony/security-http              v4.4.10 v4.4.10 Symfony Security Component - HTTP Integration
symfony/serializer                 v4.4.10 v4.4.10 Symfony Serializer Component
symfony/service-contracts          v2.1.3  v2.1.3  Generic abstractions related to writing services
symfony/stopwatch                  v4.4.10 v4.4.10 Symfony Stopwatch Component
symfony/string                     v5.1.2  v5.1.2  Symfony String component
symfony/swiftmailer-bundle         v3.4.0  v3.4.0  Symfony SwiftmailerBundle
symfony/templating                 v4.4.10 v4.4.10 Symfony Templating Component
symfony/translation                v4.4.10 v4.4.10 Symfony Translation Component
symfony/translation-contracts      v2.1.3  v2.1.3  Generic abstractions related to translation
symfony/twig-bridge                v4.4.10 v4.4.10 Symfony Twig Bridge
symfony/twig-bundle                v4.4.10 v4.4.10 Symfony TwigBundle
symfony/validator                  v4.4.10 v4.4.10 Symfony Validator Component
symfony/var-dumper                 v4.4.10 v4.4.10 Symfony mechanism for exploring and dumping PHP variables
symfony/var-exporter               v4.4.10 v4.4.10 A blend of var_export() + serialize() to turn any serializable data structure to plain PHP code
symfony/web-link                   v4.4.10 v4.4.10 Symfony WebLink Component
symfony/web-profiler-bundle        v4.4.10 v4.4.10 Symfony WebProfilerBundle
symfony/yaml                       v4.4.10 v4.4.10 Symfony Yaml Component

PHP version

$ php -v
PHP 7.2.31 (cli) (built: May 15 2020 14:32:37) ( NTS ) 
Docker image

Subject

sonata-project/admin-bundle:3.72

Error in edit entity page:

Argument 3 passed to Sonata\AdminBundle\Manipulator\ObjectManipulator::callSetter() must be of the type string, null given, called in /var/www/site/vendor/sonata-project/admin-bundle/src/Manipulator/ObjectManipulator.php on line 63

sonata-project/admin-bundle:3.71 and low - ok, no problem

Steps to reproduce

Entities:

class User{
     /**
     * Many-To-One, Unidirectional . image_id - nullable
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Image", cascade={"persist", "remove"})
     * @ORM\JoinColumn(name="image_id", referencedColumnName="id")
     */
    protected $image;
} 

class UserAdmin{
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper->add('image', AdminType::class);
    }
} 
  1. Open create User Entity page - ok
  2. Open edit User Entity page (user have image) - ok
  3. Open edit User Entity page (user have not image) - Argument 3 passed to Sonata\AdminBundle\Manipulator\ObjectManipulator::callSetter() must be of the type string, null given, called in /var/www/site/vendor/sonata-project/admin-bundle/src/Manipulator/ObjectManipulator.php on line 63
@DExploN DExploN changed the title Bug AdminType filed: Argument 3 passed to Sonata\AdminBundle\Manipulator\ObjectManipulator::callSetter() must be of the type string, null given Bug AdminType field: Argument 3 passed to Sonata\AdminBundle\Manipulator\ObjectManipulator::callSetter() must be of the type string, null given Jul 22, 2020
@VincentLanglet
Copy link
Member

In your database, many users are related to one image ?
Do you have a repository to reproduce/debug the issue ?

$associationMapping['mappedBy'] seems to be null

@DExploN
Copy link
Author

DExploN commented Jul 22, 2020

In your database, many users are related to one image ?

Yes.

Do you have a repository to reproduce/debug the issue ?

No. Its private repository

$associationMapping['mappedBy'] seems to be null

Yes. I was debugging the code and I think there is a bug in relationship maps for Many-to-one. Sonata tries to find a directive mappedBy and cannot find it.

  1. I wrote mappedBy and inversedBy, but $associationMapping['mappedBy'] ==null .
  2. I set $associationMapping['mappedBy']='image' in debug console. Why was the sonata trying to find $image->setImage() instead $user->setImage()

@DExploN
Copy link
Author

DExploN commented Jul 22, 2020

In your database, many users are related to one image ?

One-to-one not work too

@VincentLanglet
Copy link
Member

VincentLanglet commented Jul 22, 2020

I think I only worked and tested with bi-directionnal entities.

Can you try this branch #6219 ?

  1. I set $associationMapping['mappedBy']='image' in debug console. Why was the sonata trying to find $image->setImage() instead $user->setImage()

The idea here was to the the user to the image in order to add check in the image admin.
For instance, you may want to write if (!$subject->getUser()->isAdult()) { ... }.

Previously $user->setImage / $user->addImage was called, but it'll end up with some bug with the validation.
See : #6166
I changed for $image->setUser(), this fixed the previous bug.

But I didn't think about unidirectional relation.
An early return fix the issue.

There is no point trying to set anything for unidirectional relation since in the subject admin (image here) you can't access the parent.

@DExploN
Copy link
Author

DExploN commented Jul 22, 2020

Can you try this branch #6219 ?

Dont know how pull your branch in my project...
But I copy/paste your commit in vendor folder. Its work, no bug!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants