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

Skip to content

SimpleObjectHydrator: skip unsuit custom type before convert it#8566

Merged
greg0ire merged 1 commit into
doctrine:2.8.xfrom
tweet9ra:bug/#8565-simple-object-hydrator-skip-unnecessary-types-convertion
May 15, 2021
Merged

SimpleObjectHydrator: skip unsuit custom type before convert it#8566
greg0ire merged 1 commit into
doctrine:2.8.xfrom
tweet9ra:bug/#8565-simple-object-hydrator-skip-unnecessary-types-convertion

Conversation

@tweet9ra
Copy link
Copy Markdown
Contributor

SimpleObjectHydrator tries to convert the value, and only then checks if we need it.
This results in an error if our custom type does not get expected data to initialize php value.

@greg0ire greg0ire linked an issue Mar 27, 2021 that may be closed by this pull request
@tweet9ra tweet9ra force-pushed the bug/#8565-simple-object-hydrator-skip-unnecessary-types-convertion branch 2 times, most recently from 1e1c51f to a2a02cd Compare March 31, 2021 20:21
ehunov
ehunov previously approved these changes Apr 2, 2021
@greg0ire
Copy link
Copy Markdown
Member

greg0ire commented Apr 3, 2021

I have repaired the test suite, let's try this again.

@greg0ire greg0ire closed this Apr 3, 2021
@greg0ire greg0ire reopened this Apr 3, 2021
Comment thread tests/Doctrine/Tests/DbalTypes/Issue8565EmployeePayloadType.php Outdated
[
'p__id' => '1',
'm__type' => 'type field',
'e__type' => 'type field',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

To make sure I understand the PR: here we have a field with an incorrect value in the result set, but since we are going to build a manager object, this field should not even be examined, is that correct?
If yes, why is that field even present in the result set in the first place? And why does it have a value instead of something like null? It make no sense for a manager to have the employee type field filled in, right?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If there is a statement like this:

SELECT p0.id   AS id_1,
       p0.type AS type_2,
       p0.type AS type_3,
       p0.type AS type_4
FROM person p0
WHERE p0.discr IN ('person', 'manager', 'employee');

In result set mapping will appear:

$fieldMappings = [
    'type_2' => 'type',
    'type_3' => 'type',
    'type_4' => 'type',
];

So field has a value because there is only one column that has different types for different entities, and that's why it's not null.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@tweet9ra please don't mark conversations you did not open as resolved, what if I didn't understand the comment above?
@toshksenof thanks for your comment, I will try to understand it later, right now I'm a bit too tired for that I'm afraid. Or maybe the people I have added as reviewers will beat me to it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

After a good night's sleep, I think I finally got it:
Doctrine will select the same column several times, one for each mapping in each subclass.

@tweet9ra tweet9ra force-pushed the bug/#8565-simple-object-hydrator-skip-unnecessary-types-convertion branch from a2a02cd to 47bbc62 Compare April 19, 2021 13:05
SimpleObjectHydrator tries to convert the value, and only then checks if we need it.
This results in an error if our custom type does not get expected data to initialize php value.
@tweet9ra tweet9ra force-pushed the bug/#8565-simple-object-hydrator-skip-unnecessary-types-convertion branch from 47bbc62 to 2e499d8 Compare April 19, 2021 13:09
@ehunov
Copy link
Copy Markdown

ehunov commented May 14, 2021

@greg0ire, hi! any updates?

@greg0ire greg0ire requested review from beberlei and ostrolucky May 14, 2021 18:21
@greg0ire greg0ire merged commit 3a194ad into doctrine:2.8.x May 15, 2021
@greg0ire greg0ire added the Bug label May 15, 2021
@greg0ire greg0ire added this to the 2.8.5 milestone May 15, 2021
@greg0ire
Copy link
Copy Markdown
Member

I squash merged with a commit message that contains a more complete explanation, thanks to you both!
Next time, try to insist more on what is peculiar here (having one column mapped to 2 properties that have the same name but that are declared in 2 different child classes).

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.

SimpleObjectHydrator: skip unsuit custom type before convert it

4 participants