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

Why do you begin a transaction in your commit method?! #6258

Open
mica16 opened this issue Jan 5, 2024 · 8 comments
Open

Why do you begin a transaction in your commit method?! #6258

mica16 opened this issue Jan 5, 2024 · 8 comments
Labels

Comments

@mica16
Copy link

mica16 commented Jan 5, 2024

Bug Report

Using Doctrine 3.7.2 and Symfony 6.3.

Summary

In the EntityManager.php file, we have the wrapInTransactionmethod:

https://github.com/doctrine/orm/blob/e585a92763612455f591b44cf0482d9852cc5fc0/lib/Doctrine/ORM/EntityManager.php#L267-L284

Inside the code of $this->conn->commit() we can find that at the very end of the method:

dbal/src/Connection.php

Lines 1442 to 1448 in 6a793fb

if ($this->autoCommit !== false || $this->transactionNestingLevel !== 0) {
return $result;
}
$this->beginTransaction();
return $result;

Why to declare a nested transaction at the end without ever closing it?

Current behaviour

I noticed that when I run my integration tests, warning about "Nested Transactions..."
I was "forced" to declare "use_savepoints: true" in my doctrine.yaml.

How to reproduce

Don't declare use_savepoints: true in doctrine.yaml and run an integration test using wrapInTransaction.

Expected behaviour

Don't declare a useless nested transaction.

@mica16 mica16 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 5, 2024
@greg0ire

This comment was marked as resolved.

@mica16

This comment was marked as resolved.

@greg0ire

This comment was marked as resolved.

@mica16 mica16 reopened this Jan 5, 2024
@mica16

This comment was marked as resolved.

@mica16 mica16 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 5, 2024
@greg0ire

This comment was marked as resolved.

@greg0ire greg0ire reopened this Jan 5, 2024
@greg0ire greg0ire transferred this issue from doctrine/dbal Jan 5, 2024
@greg0ire
Copy link
Member

greg0ire commented Jan 5, 2024

Ah actually, the second code block is in doctrine/dbal, let's transfer the issue back!

@greg0ire greg0ire transferred this issue from doctrine/orm Jan 5, 2024
@greg0ire
Copy link
Member

greg0ire commented Jan 5, 2024

And to answer your question, this is done in auto-commit mode: https://www.doctrine-project.org/projects/doctrine-dbal/en/3.7/reference/transactions.html#auto-commit-mode

The new transaction is not nested, since we are inside commit(), as explained in the comment: // commits transaction and immediately starts a new one

@bassilil
Copy link

cod done?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants