Sometimes when converting a field to translatable or untranslatable the entity_translation_translatable_batch will run loop infinitely. In my specific case it was happening on the command line. This seems to be due to how it tracks the "max" number of records to be updated at the beginning vs. the number of records actually updated. For unknown reasons, the "max" number of records will lower, but the "max" value is not updated, so the batch process believes there is still progress to be made.

As a quick workaround, I suggest we check if any progress was made in the current run of the batch and, if not, it should be considered finished.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

CoderBrandon created an issue. See original summary.

CoderBrandon’s picture

WidgetsBurritos’s picture

Status: Active » Reviewed & tested by the community

+1 Not sure if this is meant to be a "final" patch or not, but this works for me.

pobster’s picture

I believe generally, Drupal core addresses these kinds of issues using the format of (something like);

  $context['finished'] = empty($context['sandbox']['max']) ? 1 : $context['sandbox']['progress'] / $context['sandbox']['max'];

See: "/modules//user/user.install:774", "/modules//user/user.install:809", "/modules//image/image.install:410"

But yeah, it works for us +1

stefanos.petrakis@gmail.com’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)

Thanks for this, much appreciated.

We should get the cause for this problem however, instead of treating the symptom. :-)
But, I would not let this fix hang for long, if my search proves fruitless.

So, I set this back to "needs more info", and will work on this in the following days trying to get the origins of the problem.
In the meantime, if we can get some more info on how to reproduce this problem consistently, twould be grand!

stefanos.petrakis@gmail.com’s picture

Sometimes

(from the issue's description)

sounds memory-related like, could you have a go at this patch that claims to handle some memory issues?
#2709211-6: Make entity_translation_translatable_batch() more drush friendly

donquixote’s picture

This entire batch thing is quite fragile I would say.

One thing I noticed:

  $query = new EntityFieldQuery();
  $result = $query
    ->fieldCondition($field_name)
    ->entityOrderBy('entity_id')
    ->age(FIELD_LOAD_REVISION)
    ->range($offset, $limit)
    ->execute();
  [..]
  foreach ($result as $entity_type => $partial_entities) {
    [..]
    if (EntityTranslationDefaultHandler::isEntityTypeRevisionable($entity_type)) {
      [..]
    }
    else {
      $entities = entity_load($entity_type, array_keys($partial_entities));
    }

Even if the entity translation revision support is not enabled, the array keys of the efq result will be revision ids, not entity ids.
So this is bound to fail.

Visible effect:
entity_load() turns out empty, the next loop has no iterations, $context['sandbox']['progress'] is not increased.

Invisible side effects:
The wrong entity gets updated..

donquixote’s picture

The more general problem is the fragile exit condition of the batch operation.
The exit condition is based on a count query that runs at the beginning of the batch.
If some content is deleted while the batch is running, the progress will never reach the initial count.

jcisio’s picture

I came on this bug and actually #7 spots right on it. ET was installed before entity_translation_update_7007(), so the entity has revision enabled but not supported, and entity_load() returns a completely wrong list (and if the entities are heavily revisionned, entity_load could returns an empty list and we are stuck in an infinite loop).

I don't know if we should fix it or leave the website in this state. But I'll try the other patch to at least make the batch works.