New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SimpleObjectHydrator produces wrong values with inheritance table and simple array type #5989

Closed
w3sami opened this Issue Aug 24, 2016 · 5 comments

Comments

Projects
None yet
2 participants
@w3sami

w3sami commented Aug 24, 2016

I am getting empty array instead of array with some values, since SimpleObjectHydrator converts the value with convertToPHPValue

line 129 $value = $type->convertToPHPValue($value, $this->_platform);

this doesent play well with the null check below

line 134:
// Prevent overwrite in case of inherit classes using same property name (See AbstractHydrator)
if ( ! isset($data[$fieldName]) || $value !== null) {
$data[$fieldName] = $value;
}

since arrayType->convertToPHPValue returns [] when null, resulting in a leak from the wrong left joined table.

solution is easy, dont use the converted value in the if, but instead a raw value.

eg line 125 + $rawValue = $value;
and
136: if ( ! isset($data[$fieldName]) || $rawValue !== null) {

sorry I don't have time to write a pr with tests

@Ocramius

This comment has been minimized.

Show comment
Hide comment
@Ocramius

Ocramius Aug 24, 2016

Member

since arrayType->convertToPHPValue returns [] when null, resulting in a leak from the wrong left joined table.

Seems like an issue with the array type, rather than with the ORM itself?

Member

Ocramius commented Aug 24, 2016

since arrayType->convertToPHPValue returns [] when null, resulting in a leak from the wrong left joined table.

Seems like an issue with the array type, rather than with the ORM itself?

@w3sami

This comment has been minimized.

Show comment
Hide comment
@w3sami

w3sami Aug 24, 2016

SimpleObjectHydrator is the file with the problem, type is ok imo. Same
issue is with eg json array type. Hydrator compares with type converted
version not raw value.
For me it makes sense that null is empty array for array type.

On Aug 24, 2016 8:23 PM, "Marco Pivetta" notifications@github.com wrote:

since arrayType->convertToPHPValue returns [] when null, resulting in a
leak from the wrong left joined table.

Seems like an issue with the array type, rather than with the ORM itself?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#5989 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ADiuoZhEIsq1rNG-ucjKzXaAhE9JTgyQks5qjH31gaJpZM4Jr3Ns
.

w3sami commented Aug 24, 2016

SimpleObjectHydrator is the file with the problem, type is ok imo. Same
issue is with eg json array type. Hydrator compares with type converted
version not raw value.
For me it makes sense that null is empty array for array type.

On Aug 24, 2016 8:23 PM, "Marco Pivetta" notifications@github.com wrote:

since arrayType->convertToPHPValue returns [] when null, resulting in a
leak from the wrong left joined table.

Seems like an issue with the array type, rather than with the ORM itself?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#5989 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ADiuoZhEIsq1rNG-ucjKzXaAhE9JTgyQks5qjH31gaJpZM4Jr3Ns
.

@w3sami

This comment has been minimized.

Show comment
Hide comment
@w3sami

w3sami Aug 29, 2016

bumb! this is actually a quite serious bug, as it renders all our entities with joined inheritance + (json/)array type useless!!

w3sami commented Aug 29, 2016

bumb! this is actually a quite serious bug, as it renders all our entities with joined inheritance + (json/)array type useless!!

cvuorinen added a commit to cvuorinen/doctrine2 that referenced this issue Sep 2, 2016

Create a failing test for issue #5989
Field with type=array in a joined inheritance gets overridden by empty array in the hydrator

cvuorinen added a commit to cvuorinen/doctrine2 that referenced this issue Sep 2, 2016

Create a failing test for issue #5989
Field with type=array in a joined inheritance gets overridden by empty array in the hydrator

cvuorinen added a commit to cvuorinen/doctrine2 that referenced this issue Sep 3, 2016

Create a failing test for issue #5989
Field with type=simple_array in a joined inheritance gets overridden by empty array in the hydrator

cvuorinen added a commit to cvuorinen/doctrine2 that referenced this issue Sep 3, 2016

Fix hydration in a joined inheritance with simple array or json array
SimpleArrayType and JsonArrayType convert NULL value to an empty array, which fails the null check that is used to prevent overwrite
Fixes issue #5989
@Ocramius

This comment has been minimized.

Show comment
Hide comment
@Ocramius

Ocramius Sep 7, 2016

Member

The fix in #6004 seems good, besides minor cleanup needed :-)

Member

Ocramius commented Sep 7, 2016

The fix in #6004 seems good, besides minor cleanup needed :-)

@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 added a commit that referenced this issue Sep 8, 2016

Create a failing test for issue #5989
Field with type=simple_array in a joined inheritance gets overridden by empty array in the hydrator

Ocramius added a commit that referenced this issue Sep 8, 2016

Fix hydration in a joined inheritance with simple array or json array
SimpleArrayType and JsonArrayType convert NULL value to an empty array, which fails the null check that is used to prevent overwrite
Fixes issue #5989

Ocramius added a commit that referenced this issue Sep 8, 2016

Merge branch 'fix/#6004-#5989-fix-hydration-in-a-joined-inheritance-w…
…ith-simple-array-or-json-array-2.5' into 2.5

Close #6004
Close #5989

Ocramius added a commit that referenced this issue Sep 8, 2016

Create a failing test for issue #5989
Field with type=simple_array in a joined inheritance gets overridden by empty array in the hydrator

Ocramius added a commit that referenced this issue Sep 8, 2016

Fix hydration in a joined inheritance with simple array or json array
SimpleArrayType and JsonArrayType convert NULL value to an empty array, which fails the null check that is used to prevent overwrite
Fixes issue #5989

@Ocramius Ocramius closed this in 5eebdcf Sep 8, 2016

@Ocramius

This comment has been minimized.

Show comment
Hide comment
@Ocramius

Ocramius Sep 8, 2016

Member

Fixed in #6004, thanks @w3sami and @cvuorinen!

Member

Ocramius commented Sep 8, 2016

Fixed in #6004, thanks @w3sami and @cvuorinen!

yvoyer added a commit to yvoyer/doctrine2 that referenced this issue Nov 21, 2016

Create a failing test for issue #5989
Field with type=simple_array in a joined inheritance gets overridden by empty array in the hydrator

yvoyer added a commit to yvoyer/doctrine2 that referenced this issue Nov 21, 2016

Fix hydration in a joined inheritance with simple array or json array
SimpleArrayType and JsonArrayType convert NULL value to an empty array, which fails the null check that is used to prevent overwrite
Fixes issue #5989

alexgurrola added a commit to Sitetheory-Archive/doctrine2 that referenced this issue Apr 13, 2017

Create a failing test for issue #5989
Field with type=simple_array in a joined inheritance gets overridden by empty array in the hydrator

alexgurrola added a commit to Sitetheory-Archive/doctrine2 that referenced this issue Apr 13, 2017

Fix hydration in a joined inheritance with simple array or json array
SimpleArrayType and JsonArrayType convert NULL value to an empty array, which fails the null check that is used to prevent overwrite
Fixes issue #5989
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment