Fix hydration in a joined inheritance with simple array or json array#6004
Fix hydration in a joined inheritance with simple array or json array#6004cvuorinen wants to merge 5 commits into
Conversation
Field with type=simple_array in a joined inheritance gets overridden by empty array in the hydrator
SimpleArrayType and JsonArrayType convert NULL value to an empty array, which fails the null check that is used to prevent overwrite Fixes issue doctrine#5989
| } | ||
|
|
||
| // Check if value is null before conversion (because some types convert null to something else) | ||
| $valueIsNull = $value === null; |
There was a problem hiding this comment.
Please, use Yoda condition instead.
| class Issue5989Employee extends Issue5989Person | ||
| { | ||
| /** | ||
| * @column(type="simple_array", nullable=true) |
There was a problem hiding this comment.
case sensitivity, careful :-) (@Column)
There was a problem hiding this comment.
Yea, I think it was copy paste from some existing models you have there. There are quite a few with lowercase. But I'll fix these.
|
Looks good! Feedback is only technical/minor stuff to be fixed, but this is going to be merged once that's fixed :-) |
|
@cvuorinen this looks good! Should I take over for a merge? |
|
@Ocramius I found a way to add a unit test that also reproduces this issue and passes with the fix. |
|
@cvuorinen yes, that looks exactly like what I was asking for. |
|
OK, then it's ready for merge. |
|
Merged, thanks a lot @cvuorinen! |
Both SimpleArrayType and JsonArrayType convert the value
nullto an empty array, which fails the null check that is used to prevent overwrite (in https://github.com/doctrine/doctrine2/blob/v2.5.4/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php#L134).Fixes issue #5989
It could be debated that the issue is actually with the types that convert null to something else (especially since ArrayType actually returns null when the value is null). But changing them would be a BC break so I think it is a separate issue. Also, there is no way to know how custom types will convert null values, so it seems like a reasonable approach to check for null before the conversion since it's quite a serious bug to overwrite data in the hydrator.