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

Make serialized SQL executors forward compatible #11027

Merged
merged 1 commit into from
Nov 5, 2023

Conversation

greg0ire
Copy link
Member

@greg0ire greg0ire commented Oct 26, 2023

The idea here is that instead of having a backward compatibility layer
in the next major branch, we can have a forward compatibility layer in
this branch.

Closes #11026

@greg0ire greg0ire force-pushed the fw-compat-serialization branch 2 times, most recently from 1698084 to 70c7b9c Compare October 26, 2023 08:03
@greg0ire greg0ire force-pushed the fw-compat-serialization branch 3 times, most recently from f72e503 to 374e3bb Compare October 26, 2023 12:47
@greg0ire greg0ire marked this pull request as ready for review October 26, 2023 12:53
@greg0ire greg0ire marked this pull request as draft October 26, 2023 13:06
@greg0ire greg0ire force-pushed the fw-compat-serialization branch from 374e3bb to ec1e3dd Compare October 26, 2023 13:15
@greg0ire greg0ire marked this pull request as ready for review October 26, 2023 13:38
serialized representation becomes compatible with 3.0.x, meaning
there will not be a deprecation warning about a missing property
when unserializing data */
return array_values(array_diff(array_keys((array) $this), ["\0*\0_sqlStatements"]));
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

I did once some PHP shenanigans by creating private/protected stdClass properties just for fun. 😂

Copy link
Member

@SenseException SenseException left a comment

Choose a reason for hiding this comment

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

Next to the review I did also a check of the occurrences of used _sqlStatements in case if some were forgotten, but you get anyone of those rascals. 😁

$r = new ReflectionProperty($unserialized->getSqlExecutor(), '_sqlStatements');
$r->setAccessible(true);

$this->assertIsString($r->getValue($unserialized->getSqlExecutor()));
Copy link
Member

Choose a reason for hiding this comment

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

Even though _sqlStatements is referencing sqlStatements this test would be more understandable if you compare the contents of both properties.

Suggested change
$this->assertIsString($r->getValue($unserialized->getSqlExecutor()));
$this->assertSame($r->getValue($unserialized->getSqlExecutor()), $unserialized->getSqlExecutor()->getSqlStatements());

Maybe you want to create a separated test method for your changes instead of re-using testSerializeParserResult(). One tests the serialized ParserResult, the other your forward compatiility.

@greg0ire greg0ire force-pushed the fw-compat-serialization branch from ec1e3dd to 192bb4b Compare November 5, 2023 17:33
@derrabus
Copy link
Member

derrabus commented Nov 5, 2023

Can you add a the new format to ParserResultSerializationTest::provideSerializedSingleSelectResults()?

The idea here is that instead of having a backward compatibility layer
in the next major branch, we can have a forward compatibility layer in
this branch.
@greg0ire greg0ire force-pushed the fw-compat-serialization branch from 192bb4b to 2a9390d Compare November 5, 2023 18:57
@greg0ire greg0ire added this to the 2.17.0 milestone Nov 5, 2023
@greg0ire greg0ire merged commit f08159e into doctrine:2.17.x Nov 5, 2023
58 checks passed
@greg0ire greg0ire deleted the fw-compat-serialization branch November 5, 2023 22:27
@PhilETaylor
Copy link

upgraded from doctrine/orm: '2.17.x-dev#16028e4fd3202e21cecbd87071e46b40f7eda8bf'
to doctrine/orm: '2.17.x-dev#f08159eb87ec2feb1aaf3a25bf138704a052edd7'

and now code like this:

return $this->createQueryBuilder('a')
            ->where('a.lastVisitDate > :d')
            ->andWhere('a.username != :un')
            ->setParameter('d', (new DateTime('now'))->modify($period))
            ->setParameter('un', "rabbit")
            ->orderBy('a.lastVisitDate', 'desc')
            ->setMaxResults($limit)
            ->getQuery()
            ->getResult();

results in Exception

Doctrine\DBAL\Connection::executeQuery(): Argument #1 ($sql) must be of type string, null given, called in /var/www/current/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Exec/SingleSelectExecutor.php on line 33

@greg0ire
Copy link
Member Author

greg0ire commented Nov 6, 2023

Thanks for reporting this, I will take a look.

@greg0ire
Copy link
Member Author

greg0ire commented Nov 6, 2023

@PhilETaylor fixed

@PhilETaylor
Copy link

Awesome - thanks.

@alcohol
Copy link
Contributor

alcohol commented Nov 16, 2023

@greg0ire you sure it was fixed? Our production environment just broke while rolling out with 2.17.0. See #11063 -- from the comments it looks like I'm not the only one who ran into this also.

@greg0ire
Copy link
Member Author

@alcohol yes, I'm sure, see #11048, I added a test that covers what's reported here. What you see in #11063 must be slightly different I suppose.

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.

6 participants