Error while set a paragraph field to NULL during cron run I am using Drupal 8 and I have implemented a hook_cron to set a node field to NULL. Here is my code:

if ($lesson-&gt;field_lesson_ended_at-&gt;value &lt; $current_time &amp;&amp; $session_id &amp;&amp; count($paragraphs) &gt; 0) {
  $pids = [];
  foreach ($paragraphs as $paragraph) {
    $pids[] = $paragraph['target_id'];
  }
  $storage_handler = \Drupal::entityTypeManager()-&gt;getStorage('paragraph');
  $entities = $storage_handler-&gt;loadByProperties(['id' =&gt; $pids]);

  foreach ($entities as $entity) {
    try {
      $apiObj-&gt;forceDisconnect($session_id, $entity-&gt;get('field_session_connection_id')-&gt;value);
    } catch (Exception $e) {

    }
  }
  $storage_handler-&gt;delete($entities);
  $lesson-&gt;set("field_session_id", NULL);
  $lesson-&gt;save();
}


When cron task reaches these lines:

$lesson-&gt;set("field_session_id", NULL);
$lesson-&gt;save();


Throws the following error (capture from cron logs):

Error: Call to a member function getTranslation() on null in Drupal\Core\Entity\ContentEntityBase-&gt;hasTranslationChanges() (line 1430 of core\lib\DRupal\Core\Entity\ContentEntityBase.php)


Any ideas on how to solve this issue?
Even if the cron job is working now after you changed the order, you might get the same error later when using the saved parent entity. 

Don't delete referenced paragraph entities programmatically (now the last command after you've changed the order). The Entity Reference Revisions module is handling this automatically after all revisions referencing the paragraph are removed.