Updated: Comment #N

Problem/Motivation

When checking the UUID matching of the existing and original entity during an update, ConfigEntityBase mistakenly loads itself instead of the original entity.

Proposed resolution

Don't do that

Remaining tasks

N/A

User interface changes

N/A

API changes

N/A

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sun’s picture

tim.plunkett’s picture

Assigned: Unassigned » tim.plunkett
Priority: Normal » Major
Issue summary: View changes
Status: Active » Needs review
FileSize
30.95 KB
31.91 KB

The last submitted patch, 2: configentity-2226027-2-FAIL.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 2: configentity-2226027-2-PASS.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
FileSize
33.27 KB
1.36 KB

Yay more bugs (with fixes and test coverage)!

Status: Needs review » Needs work

The last submitted patch, 5: configentity-2226027-5.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
FileSize
36.75 KB
892 bytes

One more!

Status: Needs review » Needs work

The last submitted patch, 7: configentity-2226027-7.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
FileSize
4.02 KB
39.56 KB

Ugh, breakpoint is the worst/weirdest.

Status: Needs review » Needs work

The last submitted patch, 9: configentity-2226027-9.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review

9: configentity-2226027-9.patch queued for re-testing.

tim.plunkett’s picture

FileSize
39.38 KB

Reroll after The Great Storage Rename

Status: Needs review » Needs work

The last submitted patch, 12: configentity-2226027-12.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
FileSize
2.37 KB
39.34 KB

Heh, even git can't help me with a silly mistake like this :)

dawehner’s picture

  1. +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php
    @@ -336,9 +348,6 @@ public function save(EntityInterface $entity) {
           $return = SAVED_NEW;
    
    @@ -348,6 +357,9 @@ public function save(EntityInterface $entity) {
           $this->invokeHook('insert', $entity);
    ...
    +    // Immediately update the original ID.
    +    $entity->setOriginalId($entity->id());
    

    Does it make sense to have an original ID on entity inserts?

  2. +++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/Breakpoint.php
    @@ -106,6 +106,16 @@ class Breakpoint extends ConfigEntityBase implements BreakpointInterface {
    +   */
    +  public function id() {
    +    if (!isset($this->id)) {
    +      $this->id = $this->sourceType . '.' . $this->source . '.' . $this->name;
    +    }
    +    return $this->id;
    
    @@ -114,13 +124,6 @@ public function save() {
    -    // Build an id if none is set.
    -    // Since a particular name can be used by multiple theme/modules we need
    -    // to make a unique id.
    -    if (empty($this->id)) {
    -      $this->id = $this->sourceType . '.' . $this->source . '.' . $this->name;
    -    }
    -
    
    +++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php
    @@ -104,15 +104,22 @@ public function save() {
    -    if (empty($this->id)) {
    -      $this->id = $this->sourceType . '.' . $this->source . '.' . $this->name;
    -    }
    ...
       /**
        * {@inheritdoc}
        */
    +  public function id() {
    +    if (!isset($this->id)) {
    +      $this->id = $this->sourceType . '.' . $this->source . '.' . $this->name;
    +    }
    +    return $this->id;
    +  }
    +
    +  /**
    +   * {@inheritdoc}
    +   */
    

    I really like this

  3. +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php
    @@ -0,0 +1,723 @@
    +class ConfigEntityStorageTest extends UnitTestCase {
    

    MOAAAAAAAAH!

tim.plunkett’s picture

#15.1, the reason this is needed is if you tried to do this:

$entity = entity_create('foo);
$entity->save();
$entity->save();

Without that, the second save doesn't know what the original ID is, but knows that it's not new, and breaks.

So yes, I think it's fine to update the original ID on an insert.

tim.plunkett’s picture

FileSize
40.13 KB
3.44 KB

Added some comments for the actual changes.

sun’s picture

Status: Needs review » Reviewed & tested by the community

Excellent.

dawehner’s picture

Thank you so much to improve the documentation here!

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.x, thanks!

  • Commit 979bb62 on 8.x by catch:
    Issue #2226027 by tim.plunkett: ConfigEntityBase::preSave() tries to...
tim.plunkett’s picture

Assigned: tim.plunkett » Unassigned

Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.