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

Fix deprecated DBAL calls #8794

Merged
merged 1 commit into from
Jun 28, 2021

Conversation

derrabus
Copy link
Member

This PR fixes some calls to deprecated DBAL methods.

@greg0ire greg0ire force-pushed the improvement/dbal-depecations branch from a251249 to ddd921f Compare June 27, 2021 16:18
@greg0ire greg0ire force-pushed the improvement/dbal-depecations branch from ddd921f to afa837a Compare June 27, 2021 16:26
Copy link
Member

@beberlei beberlei left a comment

Choose a reason for hiding this comment

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

Good and simple start

@greg0ire greg0ire added this to the 2.10.0 milestone Jun 28, 2021
@greg0ire greg0ire merged commit ce8de6d into doctrine:2.10.x Jun 28, 2021
@greg0ire
Copy link
Member

Thanks @derrabus !

@@ -74,7 +74,7 @@ public function generate(EntityManager $em, $entity)
$sql = $conn->getDatabasePlatform()->getSequenceNextValSQL($this->_sequenceName);

// Using `query` to force usage of the master server in MasterSlaveConnection
$this->_nextValue = (int) $conn->query($sql)->fetchColumn();
$this->_nextValue = (int) $conn->executeQuery($sql)->fetchOne();
Copy link
Member

Choose a reason for hiding this comment

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

this change made the ORM incompatible with the PrimaryReadReplicaConnection (the new name of MasterSlaveConnection) by not respecting the comment just above it. executeQuery is the API where reads are allowed from the read replica
The alternative is to force connecting to the master here instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

Can your provide a PR to fix that? I don't use PrimaryReadReplicaConnection anywhere at the moment.

Copy link
Member

Choose a reason for hiding this comment

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

I started a Slack discussion about that, to see what is the right fix for that.

Semantically, we can have 3 kind of execution:

  • read-only queries, for which we want the result -> executeQuery, and PrimaryReadReplicaConnection let them go through the read replica (if not already connected to the primary)
  • write statements without a result (e.g. UPDATE for instance) -> executeStatement (returning the number of affected rows), , and PrimaryReadReplicaConnection automatically ensures that they go to the primary
  • statements needing write priviledges but returning a result (e.g. moving to the next value of a sequence like here) -> query and PrimaryReadReplicaConnection ensures that they go to the primary

The issue here is that query got deprecated in favor of executeQuery, meaning that we don't actually have a method for the third case anymore (which would force to add support for PrimaryReadReplicaConnection in each place needing that kind of query). To me, the right fix would be to undeprecate query (or add a new method name for that behavior, using the new return type) in DBAL, and then using it in the ORM

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.

4 participants