Memory error when updating user field with Rules I'm using the Rules module to update my user email signatures.
The rule get's triggered whenever an account is updated and performs a simple custom action.
This is the action, all it does is save a new value to the signature field (textfield, full_html).
&lt;?php

namespace Drupal\frontview_general\Plugin\RulesAction;

use Drupal\rules\Core\RulesActionBase;
use Drupal\user\Entity\User;

/**
 * Change event date status to ( selected, open, closed )
 *
 * @RulesAction(
 *   id = &quot;rules_update_signature&quot;,
 *   label = @Translation(&quot;Update User Signature&quot;),
 *   category = @Translation(&quot;Custom&quot;),
 *   context_definitions = {
 *     &quot;uid&quot; = @ContextDefinition(&quot;integer&quot;,
 *       label = @Translation(&quot;User id&quot;),
 *       description = @Translation(&quot;Specifies the id of the user that needs to be updated.&quot;)
 *     )
 *   }
 * )
 */
class UpdateSignature extends RulesActionBase {

  /**
   * {@inheritdoc}
   */
  public function doExecute($uid) {

    $user = User::load($uid);

    $first_name = $user-&gt;get(&quot;field_first_name&quot;)-&gt;value;
    $last_name = $user-&gt;get(&quot;field_last_name&quot;)-&gt;value;

    $name = $first_name . &quot; &quot; . $last_name;

    $user-&gt;set(&quot;field_signature&quot;, $name);
    $user-&gt;field_signature-&gt;format = &quot;full_html&quot;;

    $user-&gt;save();

  }
}


This all works fine until it hits the  $user-&gt;save(); part. That's where something goes wrong and I end up with this error:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /Users/lennertslabbinck/Sites/Frontview/web/core/lib/Drupal/Core/Cache/DatabaseBackend.php on line 167

This works great in other actions with other content so it probably has something to do with this being users but I can't figure out what.
Your problem is loop update user infinity. When user update, hook_entity_update will be call:
/**
 * Implements hook_entity_update().
 */
function rules_entity_update(EntityInterface $entity) {
  // Only handle content entities and ignore config entities.
  if ($entity instanceof ContentEntityInterface) {
    $entity_type_id = $entity-&gt;getEntityTypeId();
    $event = new EntityEvent($entity, [
      $entity_type_id =&gt; $entity,
      $entity_type_id . '_unchanged' =&gt; $entity-&gt;original,
    ]);
    $event_dispatcher = \Drupal::service('event_dispatcher');
    $event_dispatcher-&gt;dispatch(&quot;rules_entity_update:$entity_type_id&quot;, $event);
  }
}

soure
This event will be call your rule action. So when you call $user-&gt;save(), the hook_entity_update will call again... That's your problem. To be resolve, you can follow example.

Edit your annotation. &quot;user&quot; = @ContextDefinition(&quot;entity:user&quot;,
Update logic method doExecute
Update your rule.

Remember don't call $user-&gt;save() again.