- Issue created by @ankitv18
- Issue was unassigned.
- Status changed to Needs review
5 months ago 11:44am 7 August 2024 - Status changed to Needs work
5 months ago 10:50pm 8 August 2024 - 🇺🇸United States smustgrave
Believe will need test coverage to show the issue
- 🇮🇹Italy mondrake 🇮🇹
Run the database transaction with usage of unpile method.
Why? There should be no need to call methods from the TransactionManager in normal code.
Just get a Transaction object from the Connection, then either roll it back or destroy it.
The ID is an implementation detail, and not exposed on purpose.
Maybe if you share your use case we can discuss it.
- 🇮🇳India ankitv18
#6 Make sense of not exposing transaction ID at first place.
Call to deprecated method popTransaction() of class Drupal\Core\Database\Connection: in drupal:10.2.0 and is removed from drupal:11.0.0. Use TransactionManagerInterface methods instead.
Could you help me to fix this deprecation? I was using this $this->database->popTransaction($transaction->name()); and to replace it I've used $this->database->transactionManager()->unpile($transaction->name(), $transaction->id());
- 🇮🇹Italy mondrake 🇮🇹
Can you share the code that is triggering the deprecation? From the point where you assign $transaction to the point where you try and pop it?
popTransaction()
should not have been used either, likely - 🇮🇳India ankitv18
@mondrake below is the method where I tried to replace it with unpile method.
/** * Rename the cloned tables to the original tables. */ protected function rename() { $transaction = $this->database->startTransaction('gdpr_rename_table'); foreach (array_keys($this->tablesToAnonymize) as $table) { $gdprTable = self::GDPR_TABLE_PREFIX . $table; $this->database->schema()->dropTable($table); $this->database->schema()->renameTable($gdprTable, $table); } $this->database->popTransaction($transaction->name()); }
- Status changed to Needs review
4 months ago 8:16am 11 August 2024 - 🇮🇹Italy mondrake 🇮🇹
First of all, you are doing tables drops and renames here, which are DDL (Data Definition Language) operations. Not all DBs support transactions with DDL - most notably, MySql performs an autocommit in DDL, which vanifies the transaction.
Since you are not doing any data manipulation here, you may simply avoid to wrap your code into a transaction.
If you want to stick with it, the correct way (currently) to commit the transaction is by unsetting it
unset($transaction);
instead of calling popTransaction() or unpile(). See also the docs:
Transaction;
/**
* Removes a Drupal transaction from the stack.
*
* The unpiled item does not necessarily need to be the last on the stack.
* This method should only be called by a Transaction object going out of
* scope.
*
* This method should only be called internally by a database driver.
*
* @param string $name
* The name of the transaction.
* @param string $id
* The id of the transaction.
*
* @throws \Drupal\Core\Database\TransactionOutOfOrderException
* If a Drupal Transaction with the specified name does not exist.
* @throws \Drupal\Core\Database\TransactionCommitFailedException
* If the commit of the root transaction failed.
*/
public function unpile(string $name, string $id): void; - Status changed to RTBC
4 months ago 2:08pm 11 August 2024 - 🇮🇳India ankitv18
ankitv18 → changed the visibility of the branch 3466569-cannot-access-transaction to hidden.
- Status changed to Fixed
4 months ago 2:42pm 11 August 2024 Automatically closed - issue fixed for 2 weeks with no activity.