In my module, I am causing a case where $view->query->pager can be NULL inside template_preprocess_views_view(). Whereas $view->query->render_pager() does already guard against an empty NULL pager, the AJAX-specific code on line 124

'pager_element' => $view->query->pager->get_pager_id(),

does not. Attached is a patch to fix this.

Thanks for your consideration.

Comments

dawehner’s picture

Status: Active » Needs review

Is there a reason why you use isset and query::render_pager uses empty to check the pager?

Would it be able to write a simpletest for this :)

infojunkie’s picture

No reason: coding idioms I guess :-)

About the simpletest: sure! Can you explain briefly how to run the tests in the views/tests folder?

dawehner’s picture

You have to install http://drupal.org/project/simpletest
Therefore you need also a core patch.

infojunkie’s picture

StatusFileSize
new2.59 KB

Test attached: I render the basic view, once with a normal pager, and another by NULLifying the pager after execution and before rendering. Before the patch, the second test fails with an exception. After the patch, both tests pass.

This is my first test, so please let me know if I ommitted something :-)

dawehner’s picture

StatusFileSize
new1.34 KB

Thx. You should perhaps also test whether ther variable is set in the rendered html output.

Here is a patch for the patch + test.

infojunkie’s picture

StatusFileSize
new4.03 KB

Attached is a patch that checks for the existence of the pager element in the generated HTML. Note that the view throws 5 notices when rendered, one for each row - these notices also appear when rendering a similar view on the page through the UI. It is an unrelated problem AFAICT.

merlinofchaos’s picture

Shouldn't get_pager_id() return a 0 instead of a NULL? WE can do the check there, and then clients never have to worry about it.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

So way earl is wrong here:
1) you cannot call get_pager_id here because query->pager is not defined here
2) get_pager_id already returns 0
:)

For me this patch looks rtbc

merlinofchaos’s picture

Version: 6.x-3.0-alpha2 » 7.x-3.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Applied to 6.x-3.x -- doesn't apply to 7.x but is hopefully an easy fix. Marking for porting.

dawehner’s picture

Status: Patch (to be ported) » Fixed

It was easy

Status: Fixed » Closed (fixed)

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