2

After upgrading from 9.4.8 to 9.5.3 a problem came up (see below) so when I add more than one image in articles media field node-image, I get a 500 error.

PHP Fatal error:  Nesting level too deep - recursive dependency? in /home/www/sites1/mysite.gr/astrosnews/web/sites/default/files/php/twig/63dee130963f5_field--field-node-image.h_OFwaH9BedIr0dxUMjz2WTf6If/M-GDNVdt5tDdsesr-7jYR7Xyr_xWOPal71qHp-7K3yk.php on line 89

The line 89 mentioned above is the below but is not produced by theme code.

if (((($__internal_compile_2 = ($context["items"] ?? null)) && is_array($__internal_compile_2) || $__internal_compile_2 instanceof ArrayAccess ? ($__internal_compile_2[0] ?? null) : null) != $context["item"])) {

Do you have any idea how to solve this?

Update

code which might be the source of the problem although it is not changed

  {% if items|length > 1 and view_mode == "full" %}
    <div class="image-listing-items clearfix">
      {% for item in items %}
        {% if items[0] != item %}
          <div class="image-listing-item">
            <div{{ item.attributes.addClass('field__item') }}>{{ item.content }}</div>
          </div>
        {% endif %}
      {% endfor %}
    </div>
  {% endif %}
2
  • 1
    This is theme code, the Twig engine compiles Twig to PHP. You can force recompiling by clearing the Twig PHP cache drush ev "\Drupal::service('twig')->invalidate();". If this doesn't help then check the template field--field-node-image for anything unusual.
    – 4uk4
    Feb 5, 2023 at 10:57
  • Clearing caches didn't help and there were no changes in theme and template field--field-node-image.twig The code added in the original post seems to be the source althought nothing changed for years.
    – isin
    Feb 5, 2023 at 11:17

1 Answer 1

3

This code line is expensive to calculate and could even cause a fatal error when the arrays/objects are very large:

{% if items[0] != item %}

Instead, use the Twig loop variable:

{% if not loop.first %}
2
  • Thank you @4uk4! The change you proposed in code worked! I am using a paid theme that is not updated anymore. Even if the items where only 2 or 3, when saving article I got http 500.
    – isin
    Feb 5, 2023 at 11:48
  • item(s) contains render arrays for the field content. Such render arrays change often by updating or installing and configuring additional modules. You've reached a point where the level of nesting simply was too much or somehow the render array built a recursive loop, which only causes problems when trying to traverse the array and the objects included to compare it,
    – 4uk4
    Feb 5, 2023 at 12:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.