After updating from 8.x-1.0-beta7 to 8.x-1.0-beta9, when running drush updb I get a notice that the rabbit_hole_post_update_entity_type_id_and_entity_id_for_existing_behavior_settings post-update has started but the update never completes.

Debugging the code, I see that it is entering an infinite loop in this section of code:

 
    // Try to find out the entity_id and entity_type_id.
    $entity_id = NULL;
    $entity_type_id = NULL;
    $id_parts = explode('_', $behavior_setting->id());
    while (!$entity_type_manager->hasHandler($entity_type_id, 'storage')) {
      array_pop($id_parts);
      $entity_type_id = implode('_', $id_parts);
    }

    // Get a substring of the id. Do the string length +1 to skip the leading
    // underscore.
    $entity_id = substr($behavior_setting->id(), strlen($entity_type_id) + 1);

On my site, there are two entities for which this post-update is run. The first is a Video Tutorial content type. The second is a custom Specification entity.

For the Video Tutorial content type, the call to $behavior_setting->id() returns 'node_type_video_tutorial'. As the code iterates through the while loop, the 'tutorial' and 'video' elements are popped off the $id_parts array until the storage handler is found for $entity_type_id 'node_type' and the while loop exits. At the end of the code snippet $entity_type_id is 'node_type' and $entity_id is 'video_tutorial'.

For the custom Specification entity, the annotation blocks specifies the entity id as 'specification':

/**
 * Defines the Specification entity.
 *
 * @ingroup nrel_sws
 *
 * @ContentEntityType(
 *   id = "specification",

This custom entity has no child bundles, so there is no bundle_entity_type specified in the annotation block.

When it is processed in the post-update, the call to $behavior_setting->id() returns 'specification'. On the first time through the while loop with $entity_type_id set to NULL, the 'specification' element is popped off the $id_parts array, leaving an empty array and resulting in $entity_type_id becoming set to an empty string. Since the while loop condition remains false, $entity_type_id will again get set to an empty string and the code enters an infinite loop.

I am not sure whether this is truly a bug in the RH code or whether it's a manifestation of the custom entity being incorrectly specified.

I have indicated that this issue affects 8.x-1.0-beta9, since that is the version I am updating to from 8.x-1.0-beta7, but I think that the issue would also have occurred in 8.x-1.0-beta8 which is where the post-update was introduced.

Comments

ShaunLaws created an issue. See original summary.

sgostanyan’s picture

StatusFileSize
new931 bytes

Hi,

I had the same issue, please try that patch I made.

Reards.

sgostanyan’s picture

StatusFileSize
new931 bytes
wilfred waltman’s picture

I experienced the same issue and can confirm the patch solves this.

matroskeen’s picture

Status: Active » Needs review

Updating the status, because there is a patch.

matroskeen’s picture

Priority: Normal » Major
StatusFileSize
new1.08 KB

So now we know why the user settings were excluded 🤭

I don't think we should just skip these cases, let's populate at least entity type ID.
Here is a patch that should fix the infinite loop and make sure the entity type is there.

  • Matroskeen committed a13a649 on 8.x-1.x
    Issue #3191137 by sgostanyan, Matroskeen, ShaunLaws: Infinite loop on...
matroskeen’s picture

Status: Needs review » Fixed

Committed to 8.x-1.x.
Thanks, @all!

I'm gonna create a new release later today because it seems a major issue.

Status: Fixed » Closed (fixed)

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