Notice: Trying to get property of non-object in user_access() (line 808 ofd7/modules/user/user.module).

I get the above error once I enable commerce_backoffice_content

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

SocialNicheGuru created an issue. See original summary.

SocialNicheGuru’s picture

Title: Notice: Trying to get property of non-object in user_access() (line 808 ofd7/modules/user/user.module). » Notice: Trying to get property of non-object in user_access() (line 808 of d7/modules/user/user.module).
rajeev_drupal’s picture

Assigned: Unassigned » rajeev_drupal
rajeev_drupal’s picture

This issue is in user module not in Commerce Back-office. I have applied a patch in user module.

rajeev_drupal’s picture

Status: Active » Needs review
SocialNicheGuru’s picture

But I was user 1 when I got the error.

mglaman’s picture

Status: Needs review » Needs work

This is a generic error your menu router gets corrupt by a bad [insert a magical word here]. You're likely not being passed an object, which is why the isset works.

Can you please post a stacktrace so we can track it down? I have had this happen and would love to know is this is the module causing it.

hkovacs’s picture

Hey Matt,

I get same error after enabling commerce_backoffice_content.

Since this is caused by the backoffice module, I thinks it is best not to hack the core user module and best to figure this out.

Seems related to:
https://www.drupal.org/node/1923938
and
https://www.drupal.org/node/1894586
which has a nice screenshot
https://www.drupal.org/files/My_Commerce_Backoffice%20issue_00.png

I am attaching a screenshot of krumo expanded on the error item.

Let me know if you need anything else.

hkovacs’s picture

I just found this which seems related and useful https://www.drupal.org/node/1780004#comment-7849775

mglaman’s picture

So the issue seems to be an active view with duplicate path per https://www.drupal.org/node/1780004#comment-10393993.

hkovacs’s picture

yeah, actually found this comment #29 in the same issue https://www.drupal.org/node/1780004#comment-7682701

so it is indeed an odd one.

so obviously this stems from views, but seems specifically admin_views. and from everything i have read it seems to be an issue when two view use the same path? which other backoffice issues have patched,

i ran the query mentioned in link comment my #9 and result:

$ drush sqlq 'SELECT * FROM menu_router WHERE access_callback = "user_access" AND access_arguments LIKE "a:2:%" \G'
*************************** 1. row ***************************
             path: admin/content
   load_functions:
 to_arg_functions:
  access_callback: user_access
 access_arguments: a:2:{i:0;s:23:"access content overview";i:1;s:23:"access content overview";}
    page_callback: views_page
   page_arguments: a:2:{i:0;s:16:"admin_views_node";i:1;a:2:{i:0;s:8:"system_1";i:1;s:8:"system_1";}}
delivery_callback:
              fit: 3
     number_parts: 2
          context: 0
       tab_parent:
         tab_root: admin/content
            title: Content
   title_callback: t
  title_arguments:
   theme_callback:
  theme_arguments: a:0:{}
             type: 6
      description: Administer content and comments.
         position:
           weight: -10
     include_file: modules/node/node.admin.inc

so i grepped and found:

$ grep 'admin/content' commerce_backoffice/
commerce_backoffice/includes/views/commerce_backoffice_content.views_default.inc:343:  $handler->display->display_options['path'] = 'admin/content';
commerce_backoffice/includes/views/commerce_backoffice_content.views_default.inc:678:  $handler->display->display_options['path'] = 'admin/content/comment';
commerce_backoffice/includes/views/commerce_backoffice_content.views_default.inc:737:  $handler->display->display_options['path'] = 'admin/content/comment/approval';

so it seems to me that the fn here is not going far enough:

function commerce_backoffice_content_views_default_views_alter(&$views) {
  if (isset($views['admin_views_node'])) {
    $views['admin_views_node']->disabled = TRUE;
  }
  if (isset($views['admin_views_comment'])) {
    $views['admin_views_comment']->disabled = TRUE;
  }
}

i will delve further after lunch.

plz let me know your thoughts.

mglaman’s picture

Weird. I wonder if we have to do an unset and actually prevent the View from being registered, even if deleted.

hkovacs’s picture

where and what would you like me to test?

hkovacs’s picture

I just tested this:

function commerce_backoffice_content_views_default_views_alter(&$views) {
  if (isset($views['admin_views_node'])) {
    // $views['admin_views_node']->disabled = TRUE;
    unset($views['admin_views_node']);
  }
  if (isset($views['admin_views_comment'])) {
    // $views['admin_views_comment']->disabled = TRUE;
    unset($views['admin_views_node']);
  }
}

disabled module, enable module, cleared all cache.

still throwing errors.

hkovacs’s picture

interesting... i just reran the query from above while the values are unset and now i have 3 results:

$ drush sqlq 'SELECT * FROM menu_router WHERE access_callback = "user_access" AND access_arguments LIKE "a:2:%" \G'
*************************** 1. row ***************************
             path: admin/content
   load_functions:
 to_arg_functions:
  access_callback: user_access
 access_arguments: a:2:{i:0;s:23:"access content overview";i:1;s:23:"access content overview";}
    page_callback: views_page
   page_arguments: a:2:{i:0;s:16:"admin_views_node";i:1;a:2:{i:0;s:8:"system_1";i:1;s:8:"system_1";}}
delivery_callback:
              fit: 3
     number_parts: 2
          context: 0
       tab_parent:
         tab_root: admin/content
            title: Content
   title_callback: t
  title_arguments:
   theme_callback:
  theme_arguments: a:0:{}
             type: 6
      description: Administer content and comments.
         position:
           weight: -10
     include_file: modules/node/node.admin.inc
*************************** 2. row ***************************
             path: admin/content/comment
   load_functions:
 to_arg_functions:
  access_callback: user_access
 access_arguments: a:2:{i:0;s:19:"administer comments";i:1;s:19:"administer comments";}
    page_callback: views_page
   page_arguments: a:2:{i:0;s:19:"admin_views_comment";i:1;a:2:{i:0;s:8:"system_1";i:1;s:8:"system_1";}}
delivery_callback:
              fit: 7
     number_parts: 3
          context: 1
       tab_parent: admin/content
         tab_root: admin/content
            title: Comments
   title_callback: t
  title_arguments:
   theme_callback:
  theme_arguments: a:0:{}
             type: 134
      description: List and edit site comments and the comment approval queue.
         position:
           weight: 0
     include_file: modules/comment/comment.admin.inc
*************************** 3. row ***************************
             path: admin/content/comment/approval
   load_functions:
 to_arg_functions:
  access_callback: user_access
 access_arguments: a:2:{i:0;s:19:"administer comments";i:1;s:19:"administer comments";}
    page_callback: views_page
   page_arguments: a:2:{i:0;s:19:"admin_views_comment";i:1;a:2:{i:0;s:8:"system_2";i:1;s:8:"system_2";}}
delivery_callback:
              fit: 15
     number_parts: 4
          context: 1
       tab_parent: admin/content/comment
         tab_root: admin/content
            title: Unapproved comments
   title_callback: comment_count_unpublished
  title_arguments:
   theme_callback:
  theme_arguments: a:0:{}
             type: 132
      description:
         position:
           weight: 0
     include_file: modules/comment/comment.admin.inc
hkovacs’s picture

ok, here's an idea which makes this a views issue and not a backoffice issue:

perhaps the patch in #29 here https://www.drupal.org/node/1771140#comment-10140846 (https://www.drupal.org/files/issues/views_access_arguments-1771140-29.patch) should check if $account is an object.

since the error is

Notice: Trying to get property of non-object in user_access()

it makes sense to me that views should verify this first.

i will cross post?

hkovacs’s picture

i just did a bunch of testing on the views file per the above mentioned fn and the error wont go away, so disregard my theory in #17.

GoddamnNoise’s picture

I've just found the same problem after installing latest version of the Commerce Backoffice module.