Skip to content
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

[Paginator] Fix regression when using Custom ID type #7903

Closed
wants to merge 3 commits into from
Closed

[Paginator] Fix regression when using Custom ID type #7903

wants to merge 3 commits into from

Conversation

ostrolucky
Copy link
Member

@ostrolucky ostrolucky commented Nov 16, 2019

Continuation of #7890. Created new PR to clean the mess with huge diff, though I still left attributions via co-authors.

I have reused previous code from @Ocramius for getting id type, however if preferred, I can replace it with this smaller piece of code:

$AST           = $subQuery->getAST();
$entityManager = $subQuery->getEntityManager();
$connection    = $this->query->getEntityManager()->getConnection();
$classMetadata = $entityManager->getClassMetadata(
    $AST->fromClause->identificationVariableDeclarations[0]->rangeVariableDeclaration->abstractSchemaName
);

$identifierType = PersisterHelper::getTypeOfField(
    $classMetadata->getSingleIdentifierFieldName(),
    $classMetadata,
    $entityManager
)[0];

$ids =  array_map(static function(array $row) use ($identifierType, $connection) {
    return current($row);
    return $connection->convertToPHPValue(current($row), $identifierType);
}, $foundIdRows);

Please check if this approach is right one, as it's weird that we are now doing PHP<>DB conversions in both Paginator and WhereInWalker

@lcobucci
Copy link
Member

@ostrolucky this is basically what @Ocramius had in 39d2113 and then moved to the walker in c67a515. Which basically invalidades the changes in WhereInWalker...

I'd still prefer to keep things contained in the WhereInWalker as much as possible, have you found the root cause of why the tests fail when using custom query walkers?

@ostrolucky
Copy link
Member Author

ostrolucky commented Nov 16, 2019

It's not same. In 39d2113 was convertToDatabaseValue call happening in Paginator. It was moved in c67a515 into WhereInWalker. What I've done here is to call convertToPHPValue in Paginator. This is a reverse call. Without that, WhereInWalker will have access to ids already in database values only. That said, I don't know how much this bug has to do with custom walkers, but it's the only failing testcase we received.

@lcobucci
Copy link
Member

@ostrolucky you're right. However, I think this should have been solved by the hydrator already. I'm debugging it now.

@ostrolucky
Copy link
Member Author

Thanks. Initially I wanted to just call getResult() in Paginator, but that didn't turn out to be easy.

@lcobucci
Copy link
Member

lcobucci commented Nov 16, 2019

@ostrolucky it's related to this wonderful piece of code:

// WARNING: BC break! We know this is the desired behavior to type convert values, but this
// erroneous behavior exists since 2.0 and we're forced to keep compatibility.

The LimitSubqueryWalker creates a field which isn't mapped, causing this mess.

@lcobucci
Copy link
Member

Yeah, I managed to solve this only by addressing the issue in AbstractHydrator. Didn't do it pretty because I wanted to validate my thoughts...

I believe we should ensure that things are properly hydrated in the hydrator instead of pulling this responsibility to the paginator. Do you have any concerns @Ocramius @guilhermeblanco?

@ostrolucky
Copy link
Member Author

I like that idea

@akorz
Copy link
Contributor

akorz commented Nov 16, 2019

@ostrolucky Thank you for help :)

@ostrolucky ostrolucky changed the title [Paginator] Fix regression when using Custom ID type and custom query walkers [Paginator] Fix regression when using Custom ID type Nov 16, 2019
@ostrolucky
Copy link
Member Author

I have simplified the test case more. It doesn't have anything to do with custom walkers indeed. @lcobucci can we see your patch?

@lcobucci
Copy link
Member

Superseded by #7905

@lcobucci lcobucci closed this Nov 18, 2019
@lcobucci lcobucci removed this from the 2.6.5 milestone Nov 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants