I've had a good search around the issue queue and google, but couldn't find this one, so here goes ...

Steps to reproduce (on vanilla test site created with drush si without args):

  1. As admin, go to admin/structure/views
  2. (you might need to click "show disabled views" or something if you don't see anything on the list) - I have one test site that hid them, and another test site that showed them all by default.
  3. Click "enable" on the row for, say, "Archive"
  4. Click the path link (/archive, in our example here)
  5. Expected result: Land on page of the newly enabled view
  6. Actual result: 404 page is shown

I'm going to see if I can find out anything more in code ... hopefully will have a patch for review soon ...

Comments

dawehner’s picture

Status: Active » Postponed (maintainer needs more info)

Could you try to redo the steps but clear the menu cache after enabling the view?

In general it would be cool if you could update to the latest version of views, because there are tons of bugs fixed already.

alan evans’s picture

Thanks for the followup ...

Yes, tried a menu_rebuild() after enabling and it doesn't help ... debugging efforts are currently pointing to the enabled view (archive in my example) not getting pulled into the views_menu_alter hook by views_get_applicable_views (maybe it's somehow not deemed applicable ...).

I'll certainly give it a try on the dev branch.

alan evans’s picture

Version: 7.x-3.0-rc1 » 7.x-3.x-dev

Confirmed issue seems also present on the latest dev *release* tarball (not sure if there's any difference between that and git master, but haven't tried git in any case).

I'm going to keep debugging this menu_alter a bit ...

alan evans’s picture

Spoke too soo - it definitely does come out of views_get_applicable_views. I'll avoid running commentaries for now until I have something more concrete.

alan evans’s picture

Erm .... the disabled-and-enabled view's path has now started working, after about 10x menu_rebuild()s during debugging. It could have appeared any time after, say the 3rd though. Trying to repro on another one.

alan evans’s picture

Now appears to work after one menu_rebuild() post-enable.

It looks like I may have tested the menu_rebuild whilst still using the previous release codebase, then upgraded codebase after that test, confirmed that the view was still broken post-enable and didn't reconfirm after multiple menu_rebuilds

alan evans’s picture

.... And again, no changes to code since last test, but this time multiple menu_rebuilds are not getting the /frontpage view to enable. I'll see if my logging caught anything of interest. I might have to continue this tomorrow.

We have a fantastically intermittent bug.

alan evans’s picture

I'm probably just losing my mind ... now none of my debug logging in views_menu_alter is firing at all, on multiple menu_rebuild()s. By all appearances, the menu is not being rebuilt at all, or at the very least the menu_alter is not running. The hook is definitely registered though:

drush php-eval "print_r(module_implements('menu_alter'))"
Array
(
    [0] => comment
    [1] => views
)

alan evans’s picture

OK, so trying to debug menu_rebuild() now ...

function menu_rebuild() {
watchdog('dbg', 'MENU REBUILD START');
  if (!lock_acquire('menu_rebuild')) {
    // Wait for another request that is already doing this work.
    // We choose to block here since otherwise the router item may not
    // be available in menu_execute_active_handler() resulting in a 404.
    lock_wait('menu_rebuild');
    return FALSE;
  }

watchdog('dbg', 'MENU REBUILD START TX');
  $transaction = db_transaction();

watchdog('dbg', 'MENU REBUILD START TRY');
  try {

The first 2 of these get logged, the 3rd one ('TRY') does not. Similarly, a watchdog at the end of the func just before the return does not get logged. Curious.

menu_rebuild() does return TRUE, so it does complete.

alan evans’s picture

Solved where the debug messages were going missing, using file logging from now on ...

So, looking at this, which is called on enable (views_ui.class.php):

function set_item_state($state, $js, $input, $item) {
    ctools_export_set_object_status($item, $state); 
    menu_rebuild();
}

there is already a menu_rebuild there, and it does get called (already confirmed this), I have a lot of debug logging still in there, so now time to work out why this menu_rebuild() doesn't do the job, but another manual rebuild later does.

alan evans’s picture

So ... the issue appears to be, at the point where the menu_rebuild is called, as mentioned in #10, the view still has disabled => 1, so doesn't get considered during that menu_rebuild()... Will try and find out why that might be.

alan evans’s picture

Seems that during menu_rebuild, we're dealing with statically cached views. This can be solved in views.module like this:

function views_get_applicable_views($type) {
  // @todo: Use a smarter flagging system so that we don't have to
  // load every view for this.
  $result = array();
  $views = views_get_all_views(TRUE);

Setting the $reset param to TRUE to refresh those cached objects. I've grepped ctools and views for other uses of this function and there aren't many. I'll probably ask advice on whether we always want to reset cache when calling this function (most consistent, but could cause performance problems if used a lot) or just on this one case (when calling views_get_applicable_views('uses hook menu'))

alan evans’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new697 bytes

Attached is the patch equivalent to the change pasted above and I've tested this and it does clear up the issue: it is now possible to enable disabled views and have the menu link work immediately.

What I'm not sure about is where this function gets called elsewhere. I know there is only one instance it is used in views, but several instances of views_get_applicable_views('returns context') appear in ctools. I can't say for sure whether this cache reset on every call to views_get_applicable_views is necessary for all calls, or whether limiting it to "uses hook menu" calls would be better.

alan evans’s picture

Attached is the patch equivalent to the change pasted above and I've tested this and it does clear up the issue: it is now possible to enable disabled views and have the menu link work immediately.

What I'm not sure about is where this function gets called elsewhere. I know there is only one instance it is used in views, but several instances of views_get_applicable_views('returns context') appear in ctools. I can't say for sure whether this cache reset on every call to views_get_applicable_views is necessary for all calls, or whether limiting it to "uses hook menu" calls would be better.

alan evans’s picture

Apologies for the double post.

dawehner’s picture

Status: Needs review » Fixed

Thanks this patch seems to make sense.

alan evans’s picture

Excellent, thanks.

Status: Fixed » Closed (fixed)

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

David_Rothstein’s picture

Status: Closed (fixed) » Needs review
StatusFileSize
new434 bytes

This patch was committed, but seems to have been rolled back in #1342580: Views is aggressively resetting the ctools export cache every time it does a load all for possible performance impact.

Since the performance issue was already discussed above, let's just start by reuploading a patch and going from there.

David_Rothstein’s picture

If we're worried about performance, we could, I suppose, just do what Alan was asking above (only resetting the cache for "uses hook menu" calls). If there's any doubt, I suppose that would be the safer way to go here.

dawehner’s picture

Status: Needs review » Needs work

Well it's a question whether the fix introduced in #13 was actually a performance regression of reverting it was a regression, both is bad.

As doing it all the time will not just fly. What about using the idea from #20?
Set to "needs work" so it's not committed "because it makes sense".

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new455 bytes

So here is a small patch, which implements this idea.

Status: Needs review » Needs work

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

damiankloip’s picture

Is this possibly related to #1507368: Add hook for when the view cache is invalidated and #1513126: Enabling a default view via ctools export ui requires a menu rebuild, if "variable_set('menu_rebuild_needed', TRUE)" is used, the menu is rebuilt in the next request anyway.

leewillis77’s picture

Issue summary: View changes

I'd agree that #1513126: Enabling a default view via ctools export ui requires a menu rebuild is a duplicate. Not sure which of the two issues is more valuable to keep open - they both seem to have relevant history.

nileshlohar’s picture

StatusFileSize
new434 bytes

Reroll of patch #19 with latest release.

nileshlohar’s picture

Status: Needs work » Needs review
chris matthews’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

The 2 year old patch in #26 to views.module does not apply to the latest views 7.x-3.x-dev and if still relevant needs to be rerolled.

Checking patch views.module...
error: while searching for:
  // @todo: Use a smarter flagging system so that we don't have to
  // load every view for this.
  $result = array();
  $views = views_get_all_views();

  foreach ($views as $view) {
    // Skip disabled views.

error: patch failed: views.module:1434
error: views.module: patch does not apply
Snehal Brahmbhatt’s picture

Status: Needs work » Needs review
StatusFileSize
new433 bytes

@Chris Matthews, Please refer this updated rerolled patch & share your feedback on the same.

damienmckenna’s picture

Issue tags: -Needs reroll

damienmckenna’s picture

damienmckenna’s picture

Status: Needs review » Fixed

Committed. Thanks everyone!

Status: Fixed » Closed (fixed)

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