Ajax error on views with aggregation

Created on 28 February 2023, over 1 year ago
Updated 5 March 2024, 4 months ago

Problem/Motivation

ajax.js?v=9.5.3:448 Uncaught
Drupal.AjaxError
message
:
"\nAn AJAX HTTP error occurred.\nHTTP Result Code: 200\nDebugging information follows.\nPath: /web/admin/structure/views/ajax/handler-group/latest_activity/block_1/field/field_last_update_en\nStatusText: OK\nResponseText: TypeError: array_filter(): Argument #1 ($array) must be of type array, null given in array_filter() (line 687 of /var/www/html/web/core/modules/views/src/Plugin/views/field/EntityField.php)."
name
:

Steps to reproduce

Enable aggregation on a view , add a date field, set the aggregation to some value, try to resave.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Views 

Last updated less than a minute ago

Created by

🇧🇬Bulgaria ovidenov

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

  • Issue created by @ovidenov
  • Status changed to Postponed: needs info over 1 year ago
  • 🇳🇿New Zealand quietone New Zealand

    I happen to be testing with Views right now and saw this issue. I tried to reproduce this on Drupal 10.1.x, umami install and, so far, have not been able to.

    Can you elaborate on what you did to "set the aggregation to some value"? Thanks.

  • 🇳🇱Netherlands Rop Rotterdam

    I get a simular error:

    TypeError: array_filter(): Argument #1 ($array) must be of type array, null given in array_filter() (regel 687 van /var/www/[site]/web/core/modules/views/src/Plugin/views/field/EntityField.php)

    I can save the view though. The error occurs when trying to change the aggregation function on one of my fields from COUNT to anything else. The modal won't close.

    Drupal: 9.5.8
    Php:8.1.18

    I guess the provided patch #2 is not really a solution, since the provided value SHOULD be an array, so the question is why is it NULL instead? The problem is something other, so If we just skip handling it when it is not an array we are only hiding an error, not fixing it.

  • 🇺🇸United States mkindred

    I ran across this issue today. I was trying to create a simple admin report showing the number of images (media) attached to each node of a particular content type. (I need to limit the number of images that my client adds to an existing 'product' content type, but first we need a report showing how many he's currently using per product.)

    Here are the steps I took (in D9.5.10):

    1. Create a view for a single content type, table list of fields.
    2. Add a relationship to each of two media fields (images in my case).
    3. Add two image fields to the view, each using one of the two relationships above.
    4. Turn on aggregation. The aggregation works as expected, except that the two fields' counts are multiplied by each other.
    5. I tried to change the aggregation type for the two image fields from 'Count' to 'Count DISTINCT'. But the modal won't close, and I'm seeing an error in watchdog:

    TypeError: array_filter(): Argument #1 ($array) must be of type array, null given in array_filter() (line 687 of /var/www/html/drupal/web/core/modules/views/src/Plugin/views/field/EntityField.php)

    As mentioned in #4, I'm not sure patch #2 is the correct solution, but it prevents the error, allows me to save the aggregation settings per field, and gives me the view I want.

  • Status changed to Needs work 10 months ago
  • 🇳🇱Netherlands Lendude Amsterdam

    Closed 🐛 Aggregation in views causes ajax error Closed: duplicate as a duplicate, very similar patch there.

    Thanks for the steps to reproduce, we will need an automated test for this too.

  • 🇵🇱Poland besek

    I had the same issues, with very similar steps to reproduce as described in #5 🐛 Ajax error on views with aggregation Postponed: needs info .
    Patch from #2 🐛 Ajax error on views with aggregation Postponed: needs info wroked well for me.

  • 🇮🇹Italy Turneight

    I report the patch proposed in the discussion closed because it was duplicated

  • last update 10 months ago
    30,142 pass, 2 fail
  • last update 9 months ago
    29,477 pass
  • last update 9 months ago
    29,477 pass
  • last update 9 months ago
    30,377 pass
  • 🇫🇷France xavier.masson Haute-Normandie

    Thanks for the patch, the patch from #8 🐛 Ajax error on views with aggregation Postponed: needs info works as expected on Drupal core 9.5.11 !

  • last update 7 months ago
    30,667 pass
  • last update 7 months ago
    30,667 pass
  • 🇺🇸United States crutch

    Patch doesn't apply to 10.1.8

    When manually changing /core/modules/views/src/Plugin/views/field/EntityField.php and not changing /core/modules/views_ui/src/Form/Ajax/ConfigHandlerGroup.php then the error is gone and works normally again.

  • 🇩🇪Germany diqidoq Berlin | Hamburg | New York | London | Paris

    @#8 this hasn' addressed #6 yet. This issue needs a reroll of #2 or #8 with the points made in #6.

  • last update 5 months ago
    25,805 pass, 1,851 fail
  • 🇮🇹Italy Turneight

    #8 on drupal 10.2 and php 8.3 is still working for me.
    #2 hides the problem but does not solve it, the aggregation configuration remains blocked.
    I'm sorry but I am currently unable to develop the tests.

  • 🇩🇪Germany diqidoq Berlin | Hamburg | New York | London | Paris

    @Turneight: Thanks for coming back on this! +1

  • Status changed to Postponed: needs info 5 months ago
  • 🇳🇱Netherlands Lendude Amsterdam

    Rereading this, feels like a duplicate of 🐛 Switching on aggregation generates fatal "Column not found: 1054 Unknown column" SQL error when using multi-column Fields Needs work can somebody check if the work there helps fix their issues?

  • 🇺🇸United States crutch

    For me, this issue was happening having a view with (1) Integer (2) Embed containing a single integer field which is aggregated and a (3) Simple Math Field to achieve a result. I simply could not modify aggregation at (2) at some point and found this issue. #14 speaks to multi-column fields which I wasn't using a display field with multi-columns, but in the (2) Embed field, there is a date filter which is related to this original issue. Aggregation is applied to filters and the display integer field at (2). I assume date is a multi-column field like image.

  • 🇦🇺Australia 2pha

    #8 seems to work for me

  • i have the same issue using D10.2.3, with default theme. I get this error if i try to aggregate decimal or text fields.

    Here's the error I'm getting in javascript console:

    [Error] Failed to load resource: the server responded with a status of 500 () (ref_pollutant_category, line 0)
    [Error] AjaxError:
    An AJAX HTTP error occurred.
    HTTP Result Code: 500
    Debugging information follows.
    Path: /admin/structure/views/ajax/handler-group/recommended_ef_charts/block_2/field/ref_pollutant_category
    StatusText: error
    ResponseText: The website encountered an unexpected error. Try again later.TypeError: array_filter(): Argument #1 ($array) must be of type array, null given in array_filter() (line 692 of core/modules/views/src/Plugin/views/field/EntityField.php). Drupal\views\Plugin\views\field\EntityField->submitGroupByForm(Array, Object) (Line: 106)
    Drupal\views_ui\Form\Ajax\ConfigHandlerGroup->submitForm(Array, Object)
    call_user_func_array(Array, Array) (Line: 264)
    Drupal\views_ui\ViewUI->standardSubmit(Array, Object)
    call_user_func_array(Array, Array) (Line: 129)
    Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 67)
    Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 597)
    Drupal\Core\Form\FormBuilder->processForm('views_ui_config_item_group_form', Array, Object) (Line: 325)
    Drupal\Core\Form\FormBuilder->buildForm('Drupal\views_ui\Form\Ajax\ConfigHandlerGroup', Object) (Line: 215)
    Drupal\views_ui\Form\Ajax\ViewsFormBase->Drupal\views_ui\Form\Ajax\{closure}() (Line: 627)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 217)
    Drupal\views_ui\Form\Ajax\ViewsFormBase->ajaxFormWrapper('Drupal\views_ui\Form\Ajax\ConfigHandlerGroup', Object) (Line: 127)
    Drupal\views_ui\Form\Ajax\ViewsFormBase->getForm(Object, 'block_2', 'ajax') (Line: 38)
    Drupal\views_ui\Form\Ajax\ConfigHandlerGroup->getForm(Object, 'block_2', 'ajax', 'field', 'ref_pollutant_category')
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
    Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
    Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
    Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

    and here's the error in the recent log:

    Location: https://wfrd.ddev.site/admin/structure/views/ajax/handler-group/recommen...
    Message: TypeError: array_filter(): Argument #1 ($array) must be of type array, null given in array_filter() (line 692 of /var/www/html/web/core/modules/views/src/Plugin/views/field/EntityField.php).
    Backtrace:
    #0 /var/www/html/web/core/modules/views/src/Plugin/views/field/EntityField.php(692): array_filter(NULL)
    #1 /var/www/html/web/core/modules/views_ui/src/Form/Ajax/ConfigHandlerGroup.php(106): Drupal\views\Plugin\views\field\EntityField->submitGroupByForm(Array, Object(Drupal\Core\Form\FormState))
    #2 [internal function]: Drupal\views_ui\Form\Ajax\ConfigHandlerGroup->submitForm(Array, Object(Drupal\Core\Form\FormState))
    #3 /var/www/html/web/core/modules/views_ui/src/ViewUI.php(264): call_user_func_array(Array, Array)
    #4 [internal function]: Drupal\views_ui\ViewUI->standardSubmit(Array, Object(Drupal\Core\Form\FormState))
    #5 /var/www/html/web/core/lib/Drupal/Core/Form/FormSubmitter.php(129): call_user_func_array(Array, Array)
    #6 /var/www/html/web/core/lib/Drupal/Core/Form/FormSubmitter.php(67): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object(Drupal\Core\Form\FormState))
    #7 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(597): Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object(Drupal\Core\Form\FormState))
    #8 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(325): Drupal\Core\Form\FormBuilder->processForm('views_ui_config...', Array, Object(Drupal\Core\Form\FormState))
    #9 /var/www/html/web/core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php(215): Drupal\Core\Form\FormBuilder->buildForm('Drupal\\views_ui...', Object(Drupal\Core\Form\FormState))
    #10 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(627): Drupal\views_ui\Form\Ajax\ViewsFormBase->Drupal\views_ui\Form\Ajax\{closure}()
    #11 /var/www/html/web/core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php(217): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
    #12 /var/www/html/web/core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php(127): Drupal\views_ui\Form\Ajax\ViewsFormBase->ajaxFormWrapper('Drupal\\views_ui...', Object(Drupal\Core\Form\FormState))
    #13 /var/www/html/web/core/modules/views_ui/src/Form/Ajax/ConfigHandlerGroup.php(38): Drupal\views_ui\Form\Ajax\ViewsFormBase->getForm(Object(Drupal\views_ui\ViewUI), 'block_2', 'ajax')
    #14 [internal function]: Drupal\views_ui\Form\Ajax\ConfigHandlerGroup->getForm(Object(Drupal\views_ui\ViewUI), 'block_2', 'ajax', 'field', 'ref_pollutant_c...')
    #15 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
    #16 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(627): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #17 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
    #18 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
    #19 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #20 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
    #21 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #22 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #23 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #24 /var/www/html/web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #25 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #26 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #27 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #28 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #29 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #30 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #31 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(704): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #32 /var/www/html/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
    #33 {main}

  • Status changed to Needs work 4 months ago
  • 🇳🇿New Zealand John Pitcairn

    Re #14 and #15: This is not specific to multi-column fields. I can reproduce it with a single entityreference field in a view of commerce subscriptions.

    I can set aggregation for the field to COUNT, and apply.

    But thereafter I cannot remove or change the aggregation for the field. Clicking apply will produce the ajax error.

    Un-postponing.

  • 🇫🇷France GuillaumeDuveau Toulouse

    #8 seems to work for me too.

Production build 0.69.0 2024