The execution of module_invoke_all('views_default_views') by the views/includes/cache.inc file results in an error and/or incorrect returned data due to module_invoke_all's use of the array_merge_recursive which barfs on seeing the recursion within a views object (View -> Handler -> View etc). The included patch fixes this issue.

This issue could also be fixed by changing array_merge_recursive in module_invoke_all to array_merge, although this may affect other modules that rely on the recursive nature of module_invoke_all.

Comments

sdrycroft’s picture

Status: Active » Closed (fixed)

It looks like this is the result of an upgrade from Drupal 5 (and its associated views module) to Drupal 6. I'm not experiencing this on a brand new site with exactly the same modules installed as the problem site.

I'm closing this issue for now, until I've investigated it further.

sdrycroft’s picture

Title: module_invoke_all('views_default_views') results in an error due to recursion » Duplicate view causes module_invoke_all('views_default_views') error due to recursion
Status: Closed (fixed) » Needs work
StatusFileSize
new1.56 KB

I've looked further into this, and have discovered that the issue is caused by two different modules each trying to define views with the same "View name". module_invoke_all is never going to successfully merge views with the same "View name" (due to a view objects recursion), so the proposed patch instead calls each hook individually, adding the view to the array to cache if a view with that name isn't already present. It also calls watchdog if two views with the same name exist (allowing a site administrator to possibly do something about it).

sdrycroft’s picture

Title: Duplicate view causes module_invoke_all('views_default_views') error due to recursion » Duplicate view name causes module_invoke_all('views_default_views') error due to recursion

Ooops!

sdrycroft’s picture

Priority: Normal » Critical
James Andres’s picture

+1
I have had similar situations arise when two developers on my team accidentally set up a view with the same name. That makes for a fun day of debugging ..

merlinofchaos’s picture

Status: Needs work » Needs review

ahh this issue got lost due to being marked needs work. Marking it needs review so that it'll show up in my patch queue.

dagmar’s picture

Version: 6.x-2.5 » 6.x-3.x-dev
Issue tags: +alpha-2 blocker
StatusFileSize
new1.53 KB

I have relloled this patch against Views 3.x following the Coding Standards and made the patch using cvs diff -up to make easy the review.

dawehner’s picture

StatusFileSize
new1.32 KB
+++ includes/cache.inc	10 Dec 2009 03:39:37 -0000
@@ -110,12 +110,22 @@ function _views_discover_default_views()
+                watchdog('view', "View name '$name' is already taken", array(), WATCHDOG_ERROR);

Watchdog uses

    return t($dblog->message, unserialize($dblog->variables));

to be able to translate the output, so a dynamic parameter like $name could fill the locale database.

I'm on crack. Are you, too?

merlinofchaos’s picture

Status: Needs review » Fixed

Committed to all branches.

Status: Fixed » Closed (fixed)

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

dawehner’s picture

Issue tags: -alpha-2 blocker

remove tag

kenorb’s picture

This feature changed the way how views are imported.
After implementing this patch, some of my views disappeared.
It happen, because this code calling hook_views_default_views TWICE!

      $defaults = module_invoke_all('views_default_views');
...
      foreach(module_implements('views_default_views') as $module) {

Following code doesn't work after this patch:

/**
 * Implementation of hook_views_default_views()
 */
function hook_views_default_views() {
    $views = array();
    $path = drupal_get_path('module', 'my_module') . '/views';
    $files = drupal_system_listing('.inc$', $path, 'name', 0);
    foreach ($files as $file) {
        include_once "$file->filename";
    }
    return $views;
}

I know that's maybe not the right way to import views, but the fact is that it broke some Views on the server after Views upgrade.

iva2k’s picture

Status: Closed (fixed) » Needs work

Given relevant discussion here I'm reopening this instead of creating a new issue.

1) Patch in #8 adds new but does not remove old call to hook_views_default_views, which makes every *_views_default_views() called twice (see line $default = module_invoke... at the top of the patch)

2) Code in #12 should be '"include" instead of "include_once" to be repeatable

Same problem as #12 happens in advanced_forum #687196: Fatal Error with core-overrides

iva2k’s picture

Status: Needs work » Needs review
StatusFileSize
new418 bytes

Since patch in #8 is committed to all branches, the fix is a one liner.

Patch attached. Tested.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

I think i wrote a patch alreay, but this patch looks fine, too.

merlinofchaos’s picture

Version: 6.x-3.x-dev » 6.x-2.8
Status: Reviewed & tested by the community » Fixed

This patch only appears to apply to the 2.x branch, and is not needed for 3.x -- someone please confirm that for me. In the meantime, committed to 2.x

kenorb: While your use of include_once did help us discover a bug (perhaps we need tests here) it also should be highlighted that there are valid cases where default views will be loaded twice in a single page load -- in particular, during testing -- so you should use include and not include_once to ensure your views are always included.

dawehner’s picture

yeah this is not needed for 3.x

Status: Fixed » Closed (fixed)

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