-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Conversation
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, []]); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); | |||
|
There was a problem hiding this comment.
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 :
dbal/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php
Lines 354 to 363 in 1372a42
public function testUserProvidedPDOConnection(): void | |
{ | |
$connection = DriverManager::getConnection([ | |
'pdo' => new PDO('sqlite::memory:'), | |
]); | |
$result = $connection->executeQuery('SELECT 1'); | |
self::assertInstanceOf(ForwardCompatibility\Result::class, $result); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
2.12.x is no longer maintained, please target 2.13 instead. |
lib/Doctrine/DBAL/Connection.php
Outdated
@@ -193,8 +195,20 @@ public function __construct( | |||
$this->_driver = $driver; | |||
$this->params = $params; | |||
|
|||
// check for existing pdo object |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
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. |
Please rebase on top of |
Rebase pushed |
Any luck getting this one pushed? It is preventing us from updating some of our dependencies. Thanks for all of your hard work everyone! 💯 |
Somehow I missed all the updates after my last review. Will take a look. Thanks for the reminder, @andrewkhan1. |
There was a problem hiding this 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.
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. |
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
Thanks, @bizurkur. |
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
Also, I love Doctrine. You all are doing awesome work!