I am creating a view for a specific file ID, which is passed as URL argument. When viewing this view as non-administrator, there is an SQL warning. For example with file ID 334 as argument:

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 'nid WHERE (na.grant_view >= 1 AND ((na.gid = 0 AND na.realm = 'all') OR (na.gid ' at line 1 query: title /* currentusername : title */ SELECT DISTINCT f.filename FROM files f INNER JOIN node_access na ON na.nid = 334.nid WHERE (na.grant_view >= 1 AND ((na.gid = 0 AND na.realm = 'all') OR (na.gid = 0 AND na.realm = 'og_public') OR (na.gid = 1 AND na.realm = 'og_admin') OR (na.gid = 2 AND na.realm = 'og_subscriber'))) AND ( f.fid = 0) in /path/views/modules/system/views_handler_argument_file_fid.inc on line 10.

This is a warning only - the output is correct and unaffected.

This issue seems related to node_access:
-When I view this as administrator, there is no warning.
-When I add a gid=0 nid=0 realms "all" entry in the node_access table, everything works fine
-When I give the current user role "administer nodes permission", the problem is solved.
However, all of this is not adviseable since all nodes are private.

It looks like user is not allowed by Views to view FID even though it is the owner of this file, plus author of the node this file is attached to.

Using DEVEL I could isolate the query, which is different when it's run as user that receives the warning (node author + file uploader) and when run as admin.

Node author/file uploader:
SELECT DISTINCT f.filename FROM files f INNER JOIN node_access na ON na.nid = 334.nid WHERE (na.grant_view >= 1 AND ((na.gid = 0 AND na.realm = 'all') OR (na.gid = 0 AND na.realm = 'og_public') OR (na.gid = 1 AND na.realm = 'og_admin') OR (na.gid = 2 AND na.realm = 'og_subscriber'))) AND ( f.fid = 0)

Admin:
SELECT DISTINCT f.filename FROM files f WHERE f.fid = 0

This is the view in question:

$view = new view;
$view->name = 'viewfile';
$view->description = '';
$view->tag = '';
$view->base_table = 'files';
$view->core = 0;
$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('fields', array(
  'filename' => array(
    'label' => 'Name',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'absolute' => 0,
      'link_class' => '',
      'alt' => '',
      'rel' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'hide_alter_empty' => 1,
    'link_to_file' => 0,
    'exclude' => 0,
    'id' => 'filename',
    'table' => 'files',
    'field' => 'filename',
    'relationship' => 'none',
  ),
));
$handler->override_option('arguments', array(
  'fid' => array(
    'default_action' => 'not found',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'breadcrumb' => '',
    'default_argument_type' => 'fixed',
    'default_argument' => '',
    'validate_type' => 'none',
    'validate_fail' => 'not found',
    'id' => 'fid',
    'table' => 'files',
    'field' => 'fid',
    'validate_user_argument_type' => 'uid',
    'validate_user_roles' => array(
      2 => 0,
      3 => 0,
      7 => 0,
      6 => 0,
      5 => 0,
      8 => 0,
    ),
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_user' => 0,
    'default_argument_fixed' => '',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'panel' => 0,
      'page' => 0,
      'promogroup' => 0,
      'release' => 0,
      'story' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_user_restrict_roles' => 0,
    'validate_argument_is_member' => 'OG_VIEWS_VALIDATE_GROUP_ADMIN',
    'validate_argument_group_node_type' => array(
      'promogroup' => 'promogroup',
    ),
    'validate_argument_php' => '',
    'override' => array(
      'button' => 'Override',
    ),
    'default_taxonomy_tid_term_page' => 0,
    'default_taxonomy_tid_node' => 0,
    'default_taxonomy_tid_limit' => 0,
    'default_taxonomy_tid_vids' => array(),
    'validate_argument_vocabulary' => array(),
    'validate_argument_type' => 'tid',
    'validate_argument_transform' => 0,
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler->override_option('items_per_page', 0);
$handler->override_option('distinct', 0);
$handler->override_option('style_plugin', 'table');
$handler->override_option('style_options', array(
  'grouping' => '',
  'override' => 1,
  'sticky' => 0,
  'order' => 'asc',
  'columns' => array(
    'dcid' => 'dcid',
    'timestamp' => 'timestamp',
  ),
  'info' => array(
    'dcid' => array(
      'sortable' => 0,
      'separator' => '',
    ),
    'timestamp' => array(
      'sortable' => 0,
      'separator' => '',
    ),
  ),
  'default' => '-1',
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'viewfile/%');
$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,
  'name' => 'navigation',
));

Comments

tiim_b’s picture

Issue summary: View changes

added more info

tiim_b’s picture

Issue summary: View changes

added this is a warning only and does not affect the output

MustangGB’s picture

Status: Active » Closed (won't fix)