Skip to content

Move fix for user provided pdo connection #4621

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

Merged
merged 1 commit into from
Jun 27, 2021
Merged

Move fix for user provided pdo connection #4621

merged 1 commit into from
Jun 27, 2021

Conversation

bizurkur
Copy link

Q A
Type bug
BC Break yes
Fixed issues #4619

Summary

Commit 4297f50 broke Connection when passing in $params['pdo']

#4590 says it should have fixed the issue, but I'm using 2.13.1 and it still seems to be broken.

I took the fix that was already applied in #4590 and moved it to the Connection class. This way it gets applied to all connections, not just connections built using the DriverManager.

If it's a good idea to keep the fix applied inside DriverManager, too, please let me know and I can add that back.

How to reproduce

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\PDO\MySQL\Driver;

$params = [
    'pdo' => new \PDO('mysql:<whatever>'),
];
$driver = new Driver();

$connection = new Connection($params, $driver);
// This is a query that Doctrine Migrations tool does:
$connection->executeQuery("SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'");

Also, I love Doctrine. You all are doing awesome work!

@bizurkur
Copy link
Author

bizurkur commented Apr 27, 2021

Oh, and I opened this PR against 2.12.x because it looked like the code had the same issue in that branch. Please let me know if I need to open a separate PR against 2.13.x or if 2.12.x will get merged into 2.13.x.

@@ -195,6 +197,7 @@ public function __construct(

if (isset($params['pdo'])) {
$this->_conn = $params['pdo'];
$this->_conn->setAttribute(PDO::ATTR_STATEMENT_CLASS, [PDODriverStatement::class, []]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should add some logic of the DriverManager here :

  • Check that pdo is a PDO instance
  • Trigger a deprecation

If we do so, I'm not sure that deprecation in DriverManager will still be useful. Someone using factory would get 2 deprecation.

Copy link
Author

Choose a reason for hiding this comment

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

  • Moved the deprecation warning to trigger from Connection and removed it from DriverManager
  • Added the PDO check

@@ -701,7 +704,7 @@ public static function dataCallConnectOnce(): iterable
public function testCallConnectOnce(string $method, array $params): void
{
$driverMock = $this->createMock(Driver::class);
$pdoMock = $this->createMock(Connection::class);
$pdoMock = $this->createMock(PDO::class);
$platformMock = $this->createMock(AbstractPlatform::class);
$stmtMock = $this->createMock(Statement::class);

Copy link
Contributor

@mdumoulin mdumoulin Apr 27, 2021

Choose a reason for hiding this comment

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

Not sure that your tests modification actually test your modification.

I would rather add a functional test where the connection is not built by DriverManager :

public function testUserProvidedPDOConnection(): void
{
$connection = DriverManager::getConnection([
'pdo' => new PDO('sqlite::memory:'),
]);
$result = $connection->executeQuery('SELECT 1');
self::assertInstanceOf(ForwardCompatibility\Result::class, $result);
}

Copy link
Author

Choose a reason for hiding this comment

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

Added

@greg0ire
Copy link
Member

2.12.x is no longer maintained, please target 2.13 instead.

@greg0ire greg0ire changed the base branch from 2.12.x to 2.13.x April 27, 2021 16:59
@@ -193,8 +195,20 @@ public function __construct(
$this->_driver = $driver;
$this->params = $params;

// check for existing pdo object
Copy link
Member

Choose a reason for hiding this comment

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

This comment is redundant. The code is self-explanatory.

Copy link
Author

Choose a reason for hiding this comment

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

Removed

@morozov
Copy link
Member

morozov commented May 2, 2021

Property Doctrine\DBAL\Connection::$_conn (Doctrine\DBAL\Driver\Connection|null) does not accept PDO.

This error probably will have to be suppressed since the library violates its own API by allowing a PDO instance to be used instead of a driver connection.

@morozov
Copy link
Member

morozov commented May 2, 2021

Please rebase on top of 2.13.x to fix the MySQL build failures (see #4625).

@bizurkur
Copy link
Author

Please rebase on top of 2.13.x to fix the MySQL build failures (see #4625).

Rebase pushed

@andrewkhan1
Copy link

Any luck getting this one pushed? It is preventing us from updating some of our dependencies. Thanks for all of your hard work everyone! 💯

@morozov
Copy link
Member

morozov commented Jun 14, 2021

Somehow I missed all the updates after my last review. Will take a look. Thanks for the reminder, @andrewkhan1.

Copy link
Member

@morozov morozov left a comment

Choose a reason for hiding this comment

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

Looks good overall. Please see the comments and squash commits.

@bizurkur
Copy link
Author

Sorry, but I'm just gonna close this. The PR was meant to be an extremely simple fix to move the code from #4590 into another class, nothing more. Yet it seems like each time I make the changes you guys ask for, you review it again and ask for different changes. I was only trying to move one line of code to a better location.

Feel free to re-open, copy/paste to a new PR, do whatever you want. I personally don't need this fix anymore so I've lost interest.

@bizurkur bizurkur closed this Jun 15, 2021
@greg0ire greg0ire reopened this Jun 15, 2021
@greg0ire greg0ire requested a review from morozov June 15, 2021 07:20
@greg0ire
Copy link
Member

Come on! I hate it when a contributor gets discouraged at 99% of the task! Let me do the remaining 1%, it would be a shame to waste your efforts so close to the finish line.

The goal is to apply the fix to all connections, not just connections
built using the DriverManager.
Fixes #4619
@morozov morozov merged commit 6fe08ab into doctrine:2.13.x Jun 27, 2021
@morozov
Copy link
Member

morozov commented Jun 27, 2021

Thanks, @bizurkur.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ensureForwardCompatibilityStatement broke existing code
5 participants