Here's a super simple view, just a view of node teasers with no filters and no arguments, set to Distinct='yes'. It results in invalid SQL if I have OG access control turned on, even though I'm not using anything related to OG in the view. The error goes away if I disable OG access control.

We found a trick to keep this from happening in Views 1, but I forget what it was. I think we added a dummy value as the first item in the field list. I haven't found a fix yet, so no patch.

user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DISTINCT(node.nid) FROM node node LIMIT 0, 10' at line 1 query: SELECT DISTINCT(node.nid) AS DISTINCT(node.nid) FROM node node LIMIT 0, 10 in C:\www\drupal6\sites\all\modules\views\includes\view.inc on line 731.
$view = new view;
$view->name = 'test2';
$view->description = '';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('distinct', 1);
$handler->override_option('row_plugin', 'node');
$handler->override_option('row_options', array(
  'teaser' => 1,
  'links' => 1,
  'comments' => 0,
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'test2');
$handler->override_option('menu', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
  'name' => 'navigation',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
));
CommentFileSizeAuthor
#1 views.patch942 bytesKarenS
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

KarenS’s picture

Title: Node distinct broken » Node distinct broken when using node access control
FileSize
942 bytes

I tried all kinds of tricks to fix this and finally gave up. This is a horrible ugly hack, but it works as a temporary fix for me. I'm just posting it as a last-ditch solution until someone finds a better fix.

merlinofchaos’s picture

Status: Active » Closed (duplicate)

This is a core bug -- http://drupal.org/node/284392 -- there's a patch there.