EasyCorp / EasyAdminBundle

EasyAdmin is a fast, beautiful and modern admin generator for Symfony applications.
MIT License
4.09k stars 1.03k forks source link

The property "App\Entity\TypeDictionary::$id" is not readable because it is typed "int". You should initialize it or declare a default value instead #6549

Open danfoley opened 1 week ago

danfoley commented 1 week ago

Create a new item in easy admin results in this bug:

The property "App\Entity\TypeDictionary::$id" is not readable because it is typed "int". You should initialize it or declare a default value instead
Symfony\Component\PropertyAccess\Exception\
UninitializedPropertyException
in [vendor/symfony/property-access/PropertyAccessor.php ](vendor/symfony/property-access/PropertyAccessor.php#L443)(line 443)
in [vendor/symfony/property-access/PropertyAccessor.php ](vendor/symfony/property-access/PropertyAccessor.php#L102)-> readProperty (line 102)
in [vendor/easycorp/easyadmin-bundle/src/Dto/EntityDto.php ](vendor/easycorp/easyadmin-bundle/src/Dto/EntityDto.php#L106)-> getValue (line 106)
in [vendor/easycorp/easyadmin-bundle/src/Dto/EntityDto.php ](vendor/easycorp/easyadmin-bundle/src/Dto/EntityDto.php#L113)-> getPrimaryKeyValue (line 113)
in [vendor/easycorp/easyadmin-bundle/src/Factory/ActionFactory.php ](vendor/easycorp/easyadmin-bundle/src/Factory/ActionFactory.php#L204)-> getPrimaryKeyValueAsString (line 204)
in [vendor/easycorp/easyadmin-bundle/src/Factory/ActionFactory.php ](endor/easycorp/easyadmin-bundle/src/Factory/ActionFactory.php#L146)-> generateActionUrl (line 146)
in [vendor/easycorp/easyadmin-bundle/src/Factory/ActionFactory.php ](vendor/easycorp/easyadmin-bundle/src/Factory/ActionFactory.php#L73)-> processAction (line 73)
in [vendor/easycorp/easyadmin-bundle/src/Factory/EntityFactory.php ](vendor/easycorp/easyadmin-bundle/src/Factory/EntityFactory.php#L56)-> processEntityActions (line 56)
in [vendor/easycorp/easyadmin-bundle/src/Controller/AbstractCrudController.php ](vendor/easycorp/easyadmin-bundle/src/Controller/AbstractCrudController.php#L303)-> processActions (line 303)
in [vendor/symfony/http-kernel/HttpKernel.php ](vendor/symfony/http-kernel/HttpKernel.php#L183)-> new (line 183)
in [vendor/symfony/http-kernel/HttpKernel.php ](vendor/symfony/http-kernel/HttpKernel.php#L76)-> handleRaw (line 76)
in [vendor/symfony/http-kernel/Kernel.php ](vendor/symfony/http-kernel/Kernel.php#L182)-> handle (line 182)
in [vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php ](vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php#L35)-> handle (line 35)
in [vendor/autoload_runtime.php ](vendor/autoload_runtime.php#L30)-> run (line 30)
require_once('vendor/autoload_runtime.php')
in [public/index.php ](fpublic/index.php#L9)(line 9)

umask(0002);use App\Kernel;require_once dirname(__DIR__) . '/vendor/autoload_runtime.php';return static function (array $context) {    return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);};
Error
Typed property App\Entity\TypeDictionary::$id must not be accessed before initialization

To Reproduce easycorp/easyadmin-bundle upgrading from (v4.13.6 => v4.14.0) for SF v7.1.4

nicolasne commented 6 days ago

I got the same issue with my code.

I tried to dump/echo data and I found the error may come from vendor/easycorp/easyadmin-bundle/src/Factory/ActionFactory.php:204:

// here $actionDto->getName() equals Action::SAVE_AND_RETURN

if (\in_array($actionDto->getName(), [Action::INDEX, Action::NEW, Action::SAVE_AND_ADD_ANOTHER], true)) {
  $requestParameters[EA::ENTITY_ID] = null;
} elseif (null !== $entityDto) {
  $requestParameters[EA::ENTITY_ID] = $entityDto->getPrimaryKeyValueAsString();
}

I think the action SAVE_AND_RETURN has been missing in the if part. But I don't have the big picture and cannot know if there are others side effects.

Is anyone can confirm my hypothesis?