neos / neos-development-collection

The unified repository containing the Neos core packages, used for Neos development.
https://www.neos.io/
GNU General Public License v3.0
260 stars 221 forks source link

BUG: Property mapping for Asset fails if Resource is null #2753

Open gradinarufelix opened 4 years ago

gradinarufelix commented 4 years ago

Description

When passing an empty value for the resource property of an Asset (neos/media), the following exception is thrown instead of returning no Asset.

The use case is a file upload field in a FluidTemplate that is optional, so not necessarily an image must be uploaded.

Exception: Argument 1 passed to Neos\Media\Domain\Model\Image_Original::__construct() must be an instance of Neos\Flow\ResourceManagement\PersistentResource, null given

27 Neos\Media\Domain\Model\Image_Original::__construct(NULL)
26 call_user_func_array("parent::__construct", array|1|)
25 Neos\Media\Domain\Model\Image::__construct(NULL)
24 call_user_func_array(array|2|, array|1|)
23 Neos\Media\Domain\Model\Image::Flow_Aop_Proxy_invokeJoinPoint(Neos\Flow\Aop\JoinPoint)
22 Neos\Media\Domain\Model\Image::__construct(NULL)
21 ReflectionClass::newInstanceArgs(array|1|)
20 Neos\Flow\Property\TypeConverter\ObjectConverter_Original::buildObject(array|0|, "Neos\Media\Domain\Model\Image")
19 Neos\Media\TypeConverter\AssetInterfaceConverter_Original::buildObject(array|0|, "Neos\Media\Domain\Model\Image")
18 Neos\Flow\Property\TypeConverter\PersistentObjectConverter_Original::handleArrayData(array|1|, "Neos\Media\Domain\Model\Image", array|0|, Neos\Flow\Mvc\Controller\MvcPropertyMappingConfiguration)
17 Neos\Flow\Property\TypeConverter\PersistentObjectConverter_Original::convertFrom(array|1|, "Neos\Media\Domain\Model\Image", array|0|, Neos\Flow\Mvc\Controller\MvcPropertyMappingConfiguration)
16 Neos\Media\TypeConverter\AssetInterfaceConverter_Original::convertFrom(array|1|, "Neos\Media\Domain\Model\Image", array|1|, Neos\Flow\Mvc\Controller\MvcPropertyMappingConfiguration)
15 Neos\Flow\Property\PropertyMapper_Original::doMapping(array|1|, "Neos\Media\Domain\Model\Image", Neos\Flow\Mvc\Controller\MvcPropertyMappingConfiguration, array|1|)
14 Neos\Flow\Property\PropertyMapper_Original::doMapping(array|6|, "Gmedia\MediaHouse24\Core\Domain\Model\Article", Neos\Flow\Mvc\Controller\MvcPropertyMappingConfiguration, array|1|)
13 Neos\Flow\Property\PropertyMapper_Original::convert(array|6|, "Gmedia\MediaHouse24\Core\Domain\Model\Article", Neos\Flow\Mvc\Controller\MvcPropertyMappingConfiguration)
12 call_user_func_array(array|2|, array|3|)
11 Neos\Flow\ObjectManagement\DependencyInjection\DependencyProxy::__call("convert", array|3|)
10 Neos\Flow\Mvc\Controller\Argument_Original::setValue(array|6|)
9 Neos\Flow\Mvc\Controller\AbstractController_Original::mapRequestArgumentsToControllerArguments()
8 Neos\Flow\Mvc\Controller\ActionController_Original::processRequest(Neos\Flow\Mvc\ActionRequest, Neos\Flow\Mvc\ActionResponse)
7 Neos\Flow\Mvc\Dispatcher_Original::initiateDispatchLoop(Neos\Flow\Mvc\ActionRequest, Neos\Flow\Mvc\ActionResponse)
6 Neos\Flow\Mvc\Dispatcher_Original::dispatch(Neos\Flow\Mvc\ActionRequest, Neos\Flow\Mvc\ActionResponse)
5 Neos\Flow\Mvc\DispatchComponent_Original::handle(Neos\Flow\Http\Component\ComponentContext)
4 Neos\Flow\Http\Component\ComponentChain_Original::handle(Neos\Flow\Http\Component\ComponentContext)
3 Neos\Flow\Http\Component\ComponentChain_Original::handle(Neos\Flow\Http\Component\ComponentContext)
2 Neos\Flow\Http\RequestHandler::handleRequest()
1 Neos\Flow\Core\Bootstrap::run()

HTTP REQUEST:
[request was empty]

HTTP RESPONSE:
[response was empty]

PHP PROCESS:
Inode: 12887920778
PID: 123
UID: 1000
GID: 1000
User: beach

Steps to Reproduce

  1. Create a form in Fluid and add a <f:form.upload> field.
  2. Submit the form without a value.
  3. Exception is thrown instead of just returning null for the Asset.

Expected behavior

That the property mapper evaluates the whole Asset to null.

Actual behavior

Exception is thrown.

Affected Versions

Neos: 5.0.3

Flow: 6.0.3

albe commented 4 years ago

I'm still a bit stumbled on how that would have worked correctly before under same circumstances:

This lead to a null Resource in at least Flow 5.x too as of https://github.com/neos/flow-development-collection/blob/5.0/Neos.Flow/Classes/ResourceManagement/ResourceTypeConverter.php#L186 Then when the AssetConverter is triggered, it would receive the null Resource as child property and pass that to the Image constructor, which should have failed beforehand, too, since the required non-null Resource argument is there for longer. So in conclusion, something would have to be changed in the conversion process for a generic PersistentObject (which the AssetConverter extends) in Flow. But oddly, things haven't changed in the PropertyMapper of Flow for quite some time. The most notable/relevant change was support for converting to nullable target types as null and was done over a year ago (4.3.10+).

So let's first try to really reproduce the behaviour in isolation within the media package tests if possible.

Anyway, the supposed fix above still makes sense.