Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix hydration in a joined inheritance with simple array or json array#6004

Closed
cvuorinen wants to merge 5 commits into
doctrine:masterfrom
cvuorinen:issue-5989
Closed

Fix hydration in a joined inheritance with simple array or json array#6004
cvuorinen wants to merge 5 commits into
doctrine:masterfrom
cvuorinen:issue-5989

Conversation

@cvuorinen
Copy link
Copy Markdown
Contributor

Both SimpleArrayType and JsonArrayType convert the value null to 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.

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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, use Yoda condition instead.

class Issue5989Employee extends Issue5989Person
{
/**
* @column(type="simple_array", nullable=true)
Copy link
Copy Markdown
Member

@Ocramius Ocramius Sep 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

case sensitivity, careful :-) (@Column)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Ocramius Ocramius added the Bug label Sep 7, 2016
@Ocramius Ocramius added this to the 2.5.5 milestone Sep 7, 2016
@Ocramius Ocramius self-assigned this Sep 7, 2016
@Ocramius
Copy link
Copy Markdown
Member

Ocramius commented Sep 7, 2016

Looks good! Feedback is only technical/minor stuff to be fixed, but this is going to be merged once that's fixed :-)

@Ocramius
Copy link
Copy Markdown
Member

Ocramius commented Sep 8, 2016

@cvuorinen this looks good! Should I take over for a merge?

@cvuorinen
Copy link
Copy Markdown
Contributor Author

@Ocramius I found a way to add a unit test that also reproduces this issue and passes with the fix.
Does that look OK to you?

@Ocramius
Copy link
Copy Markdown
Member

Ocramius commented Sep 8, 2016

@cvuorinen yes, that looks exactly like what I was asking for.

@cvuorinen
Copy link
Copy Markdown
Contributor Author

OK, then it's ready for merge.

Ocramius added a commit that referenced this pull request Sep 8, 2016
…ith-simple-array-or-json-array-2.5' into 2.5

Close #6004
Close #5989
@Ocramius Ocramius closed this in 5eebdcf Sep 8, 2016
@Ocramius
Copy link
Copy Markdown
Member

Ocramius commented Sep 8, 2016

Merged, thanks a lot @cvuorinen!

master: 5eebdcf
2.5: d592c14

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants