When a field access module denies access to a field that is used in a combined filter, the following error occurs:

Fatal error: Call to a member function ensure_my_table() on a non-object

To reproduce, add a field access module (in my case it is profile2), and then add a field that is private to a combined filter view. Access this view from a user that does not have access to the given field.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jhedstrom’s picture

Status: Active » Needs review
FileSize
738 bytes

This resolves the issue in my testing.

Lendude’s picture

Status: Needs review » Reviewed & tested by the community

This also occurs if you have a display with overridden fields and a not overridden combined fields filter where some of the fields that are used by the filter have been removed by the override.

Easy to reproduce with just Views 3.8 and D7 Core and the following View (no field access modules needed):

$view = new view();
$view->name = 'test_combined_field_filter';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Test combined field filter';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Test combined field filter';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
  'title' => 'title',
);
$handler->display->display_options['style_options']['default'] = '-1';
$handler->display->display_options['style_options']['info'] = array(
  'title' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
);
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
/* Field: Content: Nid */
$handler->display->display_options['fields']['nid']['id'] = 'nid';
$handler->display->display_options['fields']['nid']['table'] = 'node';
$handler->display->display_options['fields']['nid']['field'] = 'nid';
/* Field: Content: Post date */
$handler->display->display_options['fields']['created']['id'] = 'created';
$handler->display->display_options['fields']['created']['table'] = 'node';
$handler->display->display_options['fields']['created']['field'] = 'created';
$handler->display->display_options['fields']['created']['date_format'] = 'long';
$handler->display->display_options['fields']['created']['second_date_format'] = 'long';
/* Field: Content: Published */
$handler->display->display_options['fields']['status']['id'] = 'status';
$handler->display->display_options['fields']['status']['table'] = 'node';
$handler->display->display_options['fields']['status']['field'] = 'status';
$handler->display->display_options['fields']['status']['not'] = 0;
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Global: Combine fields filter */
$handler->display->display_options['filters']['combine']['id'] = 'combine';
$handler->display->display_options['filters']['combine']['table'] = 'views';
$handler->display->display_options['filters']['combine']['field'] = 'combine';
$handler->display->display_options['filters']['combine']['operator'] = 'contains';
$handler->display->display_options['filters']['combine']['expose']['operator_id'] = 'combine_op';
$handler->display->display_options['filters']['combine']['expose']['label'] = 'Combine fields filter';
$handler->display->display_options['filters']['combine']['expose']['operator'] = 'combine_op';
$handler->display->display_options['filters']['combine']['expose']['identifier'] = 'combine';
$handler->display->display_options['filters']['combine']['fields'] = array(
  'title' => 'title',
  'nid' => 'nid',
  'created' => 'created',
  'status' => 'status',
);

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'test-combined-field-filter';

/* Display: Bugged page */
$handler = $view->new_display('page', 'Bugged page', 'page_1');
$handler->display->display_options['defaults']['fields'] = FALSE;
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
/* Field: Content: Nid */
$handler->display->display_options['fields']['nid']['id'] = 'nid';
$handler->display->display_options['fields']['nid']['table'] = 'node';
$handler->display->display_options['fields']['nid']['field'] = 'nid';
$handler->display->display_options['path'] = 'test-combined-field-filter/bugged';

On the URL test-combined-field-filter/bugged you will get the error

Patch applied cleanly and solved the bug.

Maybe update the comment in the patch to reflect that multiple scenario's can cause the field to not be available?

Len

pratip.ghosh’s picture

Worked for me too.

inteja’s picture

Ditto. Worked for me also. Thanks!

MLZR’s picture

When I clicked on a node (so just viewing as user1/admin) then I had error:

Fatal error: Call to a member function ensure_my_table() on a non-object in /home/techniek/public_html/sites/all/modules/views/handlers/views_handler_filter_combine.inc on line 60

So my case was somewhat different from the ones in this issue. Bud I applied the patch and the error is gone!

Thanks!

kscheirer’s picture

I had the same error as marchellodepello, patch in #1 solved it for me as well.

joelpittet’s picture

+1 to this patch, it's working well for me.

agileadam’s picture

Patch #1 worked for me as well. Thank you!

anou’s picture

Tout pareil : Patch #1 worked for me as well. Merci ! :-)

hargobind’s picture

Confirming that this patch fixes the scenario in #2.

jhedstrom’s picture

Curious if anybody knows what the process for ensuring fixes like this make it to Drupal 8 is?

joelpittet’s picture

@jhedstrom best approach that I know:

  1. open a drupal core project issue,
  2. with a VDC tag
  3. Views component for 8.0.x version
  4. Assign this issue as a related issue.
  5. Submit a patch

To get it in faster... write a test that proves the bug, preferably UnitTest but WebTest can do the trick. Post the tests only and have testbot fail and then the combo(tests+fix) showing it fixes the issue.

All assuming this bug still exists in D8.

Lendude’s picture

Opened a D8 issue for this with a port of patch in #1 with added testing.

Lendude’s picture

Ok the referencing is smart enough, so didn't have to add it here

geresy’s picture

Patch #1 worked for me. I encountered it with dev, the recommended release doesn't throw errors.

dawehner’s picture

Project: Views (for Drupal 7) » Drupal core
Version: 7.x-3.x-dev » 8.0.x-dev
Component: Miscellaneous » views.module
Status: Reviewed & tested by the community » Patch (to be ported)

That totally makes sense. Committed to 7.x-3.x and pushed

jibran’s picture

Project: Drupal core » Views (for Drupal 7)
Version: 8.0.x-dev » 7.x-3.x-dev
Component: views.module » Code
Status: Patch (to be ported) » Fixed

This is the commit to D7 http://cgit.drupalcode.org/views/commit/?id=d7837bc
Form \Drupal\views\Plugin\views\filter\Combine in D8

    // Only add the fields if they have a proper field and table alias.
    foreach ($this->options['fields'] as $id) {
      // Overridden fields can lead to fields missing from a display that are
      // still set in the non-overridden combined filter.
      if (!isset($this->view->field[$id])) {
        // If fields are no longer available that are needed to filter by, make
        // sure no results are shown to prevent displaying more then intended.
        $this->view->build_info['fail'] = TRUE;
        continue;
      }

So it seems it's already fixed.

Lendude’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

arebacollins’s picture

Having a strange recurrence of the same on views 7.x-3.11 and specifically on views field view , both dev and 7.x-1.1 versions. I tried applying the patch to views but nothing changes.
Strangely, I get this error on about 8 node items of a 46 nodes custom content type, started arbitrarily, and randomly around the time I was playing with openlayers. Since then has not resolved.

capfive’s picture

this was a rare case for me, I am using Views Field View which allows you to embed another view within a view...

Long story short, I deleted the view that was being embed and didn't remove it from master view... just in case someone rolls into this problem!

RAWDESK’s picture

okay, patch worked for me also

robgreeniowa’s picture

This error showed on a logged-in Drupal user's view page (it was a table of nodes, using a combined filter as a 'searchbox of sorts'). Only her computer - I couldn't reproduce. Simply deselecting all the fields in the combined filter caused her error to go away. I was able to re-select those fields, and the error message didn't come back. Hopefully this quick fix saves some of you some time.

kscheirer’s picture

This issue is closed. If that's an error and there still is the original issue, please re-open this issue. If there is a different problem, please open a new issue. It's unlikely anyone will see comments on a closed issue.

Drupal_8_TTerm’s picture

Sorry a stupid question, but how exactly do you apply this patch? Do you make a new file? If so what is the name of that file and if not where do I include the code of the patch in my views_handler_area_text.inc - file? Or do I include it even into a different file?

Thank you very much in advance!

Lendude’s picture

@Drupal_8_TTerm you don't need to apply this patch, this was fixed in Drupal 7 Views and Drupal 8 core. So if you still run into this on an up-to-date install, please open a new issue for this.