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

Require $platform in AbstractSchemaManager::__construct() #4146

Merged
merged 1 commit into from
Jul 6, 2020

Conversation

morozov
Copy link
Member

@morozov morozov commented Jul 4, 2020

Q A
Type bug
BC Break yes

Problem Statement

The Connection::getDatabasePlatform() method called from within AbstractSchemaManager::__construct() can throw a DBALException which is neither handled nor declared via @throws.

/**
* Constructor. Accepts the Connection instance to manage the schema for.
*/
public function __construct(Connection $conn, ?AbstractPlatform $platform = null)
{
$this->_conn = $conn;
$this->_platform = $platform ?? $this->_conn->getDatabasePlatform();
}

Not only the method throws a non-documented exception, the exception propagates undocumented to Driver::getSchemaManager() which instantiates a schema manager.

Implementations of the Driver interface cannot throw a DBALException because it doesn't belong to this level of abstraction.

Solution

Instantiate the platform in the wrapper layer and avoid the potential exception. The wrapper connection remains as lazy as it was before.

Additional notes

  1. Although the code like $this->driver->getSchemaManager($this, $this->getDatabasePlatform()) may look awkward, this weirdness is not caused by this change. The reason is that the wrapper connection is quite a god object, and the very fact that other components depend on it (e.g. instead of a driver connection) is the real issue.
  2. No upgrade path is provided. On the one hand, schema managers are supposed to be accessed via the wrapper connection; on the other, adding a new argument to an interface method (even optional) is a BC break.

greg0ire
greg0ire previously approved these changes Jul 5, 2020
@morozov morozov force-pushed the schema-manager-require-platform branch from 861ab4b to c1ed9fe Compare July 5, 2020 20:47
@morozov morozov requested a review from greg0ire July 5, 2020 21:01
@morozov morozov merged commit 4ec17a7 into doctrine:3.0.x Jul 6, 2020
@morozov morozov deleted the schema-manager-require-platform branch July 6, 2020 15:23
@morozov morozov self-assigned this Jul 6, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 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.

None yet

2 participants