Other Modules Triggering PostSave Can Cause Exception

Created on 9 November 2022, about 2 years ago
Updated 24 February 2023, almost 2 years ago

Problem/Motivation

If another module also triggers a save (like an entity_update hook), the new group content entity can be "re-saved" causing an exception.

Drupal\Core\Entity\EntityStorageException: Update existing 'group_content' entity while changing the ID is not supported. in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 811 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 802)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object) (Line: 339)
Drupal\Core\Entity\EntityBase->save() (Line: 68)
Drupal\entitygroupfield\Field\EntityGroupFieldItemList->postSave(1)
....

Proposed resolution

Once we save the group_content_entity, unset the property which executes the save.

πŸ› Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States dww

    Thanks for reporting this, and providing a fix! There's code here to review, so changing status. That should also trigger a test run, so we can see if the patch still applies, existing tests pass, etc.

  • Status changed to Needs work almost 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States dww

    Cool, nice to see the patch still applies and existing tests pass. However, I'm trying to keep good test coverage in here, so I don't want to commit any changes without tests.

Production build 0.71.5 2024