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 218 forks source link

BUG: Cannot unset `defaultValue` via `CreateNodeAggregateWithNode::$initialPropertyValues` #5154

Open mhsdesign opened 1 week ago

mhsdesign commented 1 week ago

While the change https://github.com/neos/neos-development-collection/pull/4322 improved the unset handling of properties a lot, it introduced a regression.

Using the following NodeType

'Flowpack.NodeTemplates:Content.Properties':
  properties:
    unsetValueWithDefault:
      defaultValue: true
      type: boolean

and creating it but using

PropertyValuesToWrite::fromArray(["unsetValueWithDefault" => null])

would originally set unsetValueWithDefault to NULL in the database. This was the behaviour in Neos 8.3 and Neos 9 before the mentioned change. Now when fetching the nodes properties we get the following result - the default value is still present:

-        "unsetValueWithDefault": null
+        "unsetValueWithDefault": true

The reason for that is that we filter out the unsets when creating a node (under the impression that no one would do this ^^):

https://github.com/neos/neos-development-collection/blob/7db53b6c4ec590973e063077a8c4a2ab72801c5c/Neos.ContentRepository.Core/Classes/Feature/NodeCreation/NodeCreation.php#L88

A workaround for now is to followup with a SetNodeProperties command

kitsunet commented 1 week ago

nvm deleted my previous comment I thought unsetsValueWithDefault is a feature here^^ Still seems right behavior?

mhsdesign commented 1 week ago

Hmmm i dont think its right if a followup SetNodeProperties can unset that property like i did here: (because i had to precise tests 😂 and couldnt let it slip)

https://github.com/Flowpack/Flowpack.NodeTemplates/blob/4d1ccfa71674054fe2189d2e984a8c86609d3491/Classes/Domain/NodeCreation/NodeCreationService.php#L81-L92

kitsunet commented 1 week ago

Wait what? I don't think you should be able to unset default values, you can overwrite them with other values but not remove them?

mhsdesign commented 1 week ago

😂 hahah yes sounds legit ... i just wondered a year ago what the behaviour might be and observed that its possible and put it in stone via the node template tests :D I guess there might be people relying on this ... eg setting an text field back to empty (which is null effectively by the neos ui)