Problem/Motivation
While adding a user to a Group programmatically (using the Group module API) in Drupal 10, a database transaction error is thrown when using PostgreSQL 16.
The issue occurs during entity save operations triggered by $group->addMember($user) and results in a transaction conflict. This blocks user-to-group assignment and interrupts installation flows (e.g., in custom install profiles or automated scripts).
The error suggests a nested or conflicting transaction being initiated with the same name (mimic_implicit_commit), which is not allowed.
Steps to reproduce
Set up Drupal 10 with PostgreSQL 16
Enable the Group module
Create a Group type and a Group
Programmatically add a user to the group using Drush or custom code:
$group = \Drupal\group\Entity\Group::load(1);
$user = \Drupal\user\Entity\User::load(2);
$group->addMember($user);
Execute via:
drush ev "..."
Observe the error:
Drupal\Core\Database\TransactionNameNonUniqueException:
A transaction named mimic_implicit_commit is already in use.
Proposed resolution
Investigate transaction handling in Group membership creation, especially during entity save operations.
Ensure unique transaction naming or avoid nested transactions with identical identifiers.
Add safeguards to prevent duplicate transaction stack entries when using PostgreSQL.
Review compatibility of Drupal core transaction handling with PostgreSQL 16 behavior.
Potentially wrap addMember() in a safer transaction boundary or avoid implicit commit conflicts.
Workaround ideas:
Avoid calling group membership creation inside another transaction
Use queue or deferred execution instead of immediate save during install hooks
Explicitly manage transactions when running batch/group operations
Remaining tasks
Identify exact code path causing duplicate transaction push
Confirm if issue is reproducible across PostgreSQL versions (<16 vs 16)
Test with minimal module setup (only Group + dependencies)
Add kernel test to reproduce the issue
Validate fix does not impact MySQL behavior
User interface changes
None.
API changes
Potential internal changes to transaction handling in entity/group APIs
No intended public API changes
Data model changes
None.
Comments