[PR #1471] Platform built twice on closed connections #9530

Open
opened 2026-01-22 16:04:35 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/orm/pull/1471

State: closed
Merged: No


There is a loop when a closed connection is asked for its Database Platform, in which the resulting Platform object gets overwriten by a new one and all modifications made in the postConnect event are lost.

The commited test adds the event BEFORE the connection gets opened automatically by the OrmFunctionalTestCase setUp method. I know this is not a common test scenario, but I had to make this hack in order to reuse all the other FunctionalTestCase stuff.

I believe this only happens in Drivers that implement VersionAwarePlatformDriver, as I could not reproduce it with sqlite.

I believe what's happening is:

  • Connection tries to detectPlatformDriver
  • As connection is closed, getDatabasePlatformVersion tries to $this->connect() it
  • Connection::connect() has a null on $this->platform because it didn't finish detecting, so it tries to detect again
  • This time the connection is opened, so detectPlatormDriver succedes.
  • Connection fires the event
  • The rest of the first detectPlatformDriver call executes, overriding $this->platform

I was using the postConnect event to add types only when the connection is opened, instead of adding them every time I constructed the EntityManager, to prevent connections from being opened every time.

**Original Pull Request:** https://github.com/doctrine/orm/pull/1471 **State:** closed **Merged:** No --- There is a loop when a closed connection is asked for its Database Platform, in which the resulting Platform object gets overwriten by a new one and all modifications made in the postConnect event are lost. The commited test adds the event BEFORE the connection gets opened automatically by the OrmFunctionalTestCase setUp method. I know this is not a common test scenario, but I had to make this hack in order to reuse all the other FunctionalTestCase stuff. I believe this only happens in Drivers that implement VersionAwarePlatformDriver, as I could not reproduce it with sqlite. I believe what's happening is: - `Connection` tries to `detectPlatformDriver` - As connection is closed, `getDatabasePlatformVersion` tries to `$this->connect()` it - `Connection::connect()` has a `null` on `$this->platform` because it didn't finish detecting, so it tries to detect again - This time the connection is opened, so `detectPlatormDriver` succedes. - `Connection` fires the event - The rest of the _first_ `detectPlatformDriver` call executes, overriding `$this->platform` I was using the postConnect event to add types only when the connection is opened, instead of adding them every time I constructed the EntityManager, to prevent connections from being opened every time.
admin added the pull-request label 2026-01-22 16:04:35 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#9530