PHP Fatal error: Call to a member function get_option() on null in /home/charlie/Projects/project_name/sites/all/modules/views/plugins/views_plugin_query_default.inc on line 1327

I received this error because a calling script did not utilize the view->display_handler object correctly. My submitted patch resolves this by simply adding a "&& isset($this->view->display_handler)" around that if block.

If this has already been resolved in GIT, please feel free to ignore/close this issue.

Comments

charlie_eval created an issue. See original summary.

joelpittet’s picture

Version: 7.x-3.11 » 7.x-3.x-dev
Status: Patch (to be ported) » Needs review

Setting the dev branch version and needs review to see what the testbot will say

Status: Needs review » Needs work

The last submitted patch, undefined_view_display_handler_issue.patch, failed testing.

joelpittet’s picture

The failure I think is the patch format.

Hars Saraf’s picture

This seems to be a long standing problem. I am facing the same error for line 1296 & 1327 & get WSoD when i try to create content. Would be really helpful if somebody could commit a working patch to the main repository. Sorry I am new to drupal and hence, don't know how to work with patches.
Related issues:
https://www.drupal.org/node/2617198
https://www.drupal.org/node/2134955
https://www.drupal.org/node/2480591
https://www.drupal.org/node/2679585

ccjjmartin’s picture

Here is the rerolled patch but it doesn't work.

Krilo_89’s picture

Does anyone has the views_selective_filters module enabled? Because I think that is the module which is causing the error and that's why not everyone is getting fatal errors.

Here is the rerolled patch but it doesn't work.

ccjmartin, you say your patch isn't working? Maybe I misread it, but I have include a patch which is working and looks similar to yours. I will also post why the error is thrown and commit the patch.

Inside the views_filters_selective.module on line 77 of function _views_filter_selective_query($filter, $field_name, $table_name, $oids) there's a code with a 'dummy' array. $query->view = (object)array('name' => 'dummy'); // needed to avoid PHP notice

Inside views_plugin_query_default.inc there is this line 1327:

// Allow 'GROUP BY' even no aggregation function has been set.
$this->has_aggregate = $this->view->display_handler->get_option('group_by');

$this->view is a Views class. That's why $this->view->display_handler->get_option->get_option() returns useful data. But the views_selective_filters module gives a plain stdClass instead of a View class. This causes an fatal error.

When the undefined-display-handler-2557603-6.patch is changed with the following code, everything works as expected. Websites who don't have the views_selective_filters enabled, still work as expected. But sites with views_selective_filters enabled, now don't throw fatal errors.

elseif (!$this->has_aggregate && !empty($this->view->display_handler)) {
  // Allow 'GROUP BY' even no aggregation function has been set,
  // but only when there is a legit view display_handler.
  $this->has_aggregate = $this->view->display_handler->get_option('group_by');
}
steinmb’s picture

@Krilo_89 - You need to re-roll the patch. Patches must be created within the views module, not from your root dir (Index: sites/all/modules/contrib/..). Also, if views_selective_filters module is causing problems. Why no move the issue to that module?

DamienMcKenna’s picture

Status: Needs work » Needs review
FileSize
847 bytes

Corrected patch.

Krilo_89’s picture

@steinmb, thanks for the comments! Will do it right next time.
Views Selective Filters does has this problem, but Views will throw the error every time a non-legit view display_handler is passed through it. So why not fix it inside views? When other modules make the same mistake, the won't get an error and Views is future proof for other modules.

@DamienMcKenna, I tested your patch and it works fine, so do I need to change the status?

joelpittet’s picture

@Krilo_89 yes, if you tested it please change the status to "Reviewed and Tested by the Community"

Krilo_89’s picture

Status: Needs review » Reviewed & tested by the community

@joelpittet, I changed the status.

The last submitted patch, 7: undefined-display-handler-2557603-7.patch, failed testing.

SocialNicheGuru’s picture

The only thing is that it would be nice if it logged a watchdog message about which view is the culprit. I have gotten WSOD with views_field_view because the view being referenced was not present.