I just noticed this error in my logs:

Notice: Trying to get property of non-object in apachesolr_search_apachesolr_facets() (line 847 of /DRUPAL7/sites/all/modules/contrib/apachesolr/apachesolr_search.module).

It's been occurring several times so figured it's worth reporting.

CommentFileSizeAuthor
#20 1103602-valid-vocab-20.patch758 bytespwolanin
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jpmckinney’s picture

Status: Active » Postponed (maintainer needs more info)

That line number is a bit mysterious, as in the latest 7.x-1.x it is just a closing }. Can you point out what's on that line in your version of the module?

mgifford’s picture

It's the if statement in this bit here:

        $vocab = taxonomy_vocabulary_machine_name_load($vocab['vocabulary']);
        if ($vocab->hierarchy == 1) {
          $facets[$index_key]['hierarchical'] = TRUE;
        }

Not sure why that would produce the error either, but looks like we are looking at different versions.

pwolanin’s picture

Ok, well that sounds like the vocabulary faield to load at all - do you have some deleted vocabularies?

try something like this change, though it won't fix the underlying problem:

@@ -842,7 +842,7 @@ function apachesolr_search_apachesolr_facets() {
       if ((count($vocabs) == 1)) {
         $vocab = array_shift($vocabs);
         $vocab = taxonomy_vocabulary_machine_name_load($vocab['vocabulary']);
-        if ($vocab->hierarchy == 1) {
+        if (isset($vocab->hierarchy) && $vocab->hierarchy == 1) {
           $facets[$index_key]['hierarchical'] = TRUE;
         }
       }
jpmckinney’s picture

mgifford’s picture

That worked just fine. That patch removed the php notice from the reports

The error pops up with 404 issues:

TYPE	: php
USER:	Anonymous (not verified)
LOCATION:	http://openconcept.ca/calendar/2010/09/27?filter0=**ALL**&filter1=New&filter2=11	
MESSAGE:	Notice: Trying to get property of non-object in apachesolr_search_apachesolr_facets() (line 847 of /DRUPAL7/sites/all/modules/contrib/apachesolr/apachesolr_search.module).
SEVERITY:	notice
HOSTNAME:	66.249.72.177

So yes, I expect that the vocabulary field would be hard to find.

jpmckinney’s picture

Not sure why the field would be pointing to a non-existent vocabulary. Can you dsm($vocab['vocabulary']) and verify that a vocab exists with that vocab machine name?

jpmckinney’s picture

Category: bug » support
mgifford’s picture

I did try to insert this but got a WSOD:

if (user_access('administer search')) {
  dsm($vocab['vocabulary']);
}

Not sure what I'm doing wrong here...

pwolanin’s picture

dsm is not a core function, it's from devel module. Try:

drupal_set_message('<pre>' . print_r($vocab['vocabulary'], TRUE) . '</pre>');
mgifford’s picture

Well, it's getting closer. I had to use:

if (user_access('administer search')) {
  drupal_set_message('<pre>' . print_r($vocab->vocabulary, TRUE) . '</pre>');
}

to avoid getting "Fatal error: Cannot use object of type stdClass as array" errors. However, I then got:

      <div class="messages status"> 
<h2 class="element-invisible">Status message</h2> 
 <ul> 
  <li><pre></pre></li> 
  <li><pre></pre></li> 
  <li><pre></pre></li> 
  <li><pre></pre></li> 
  <li><pre></pre></li> 
 </ul> 
</div> 

As a result. So I'm no wiser here as to the source of the problem. Perhaps it is blank vocabs, but not sure why that matters.

jpmckinney’s picture

Did you insert that code before or after:

$vocab = taxonomy_vocabulary_machine_name_load($vocab['vocabulary']);

The original $vocab['vocabulary'] version should have been inserted before that line.

mgifford’s picture

Ok, I submitted the code after as per:

        $vocab = array_shift($vocabs);
        $vocab = taxonomy_vocabulary_machine_name_load($vocab['vocabulary']);

if (user_access('administer search')) {
  drupal_set_message('<pre>' . gettype($vocab) . ' | ' .  print_r($vocab->vocabulary, TRUE) . '</pre>');
}

I added in the gettype() function as I was getting complaints about this being an object and not an array. In the 5 messages I got, 4 were objects & one was a boolean. There were no arrays.

This is consistent with the error.

pwolanin’s picture

So the boolean is a failed load it would seem

mgifford’s picture

Seems possible. So, does that help move this issue ahead?

legendfall’s picture

So does that mean the problem solved? should I change code of apachesolr_search.module as described in #12?
anybody worked this out? thanks

jpmckinney’s picture

Can you instead put:

        $vocab = array_shift($vocabs);
if (user_access('administer search')) {
  drupal_set_message('<pre>' . gettype($vocab) . ' | ' .  print_r($vocab['vocabulary'], TRUE) . '</pre>');
}
        $vocab = taxonomy_vocabulary_machine_name_load($vocab['vocabulary']);

I want to know what $vocab is before it is set to taxonomy_vocabulary_machine_name_load.

legendfall’s picture

when I put:
$vocab = array_shift($vocabs);
if (user_access('administer search')) {
drupal_set_message('

' . gettype($vocab) . ' | ' .  print_r($vocab['vocabulary'], TRUE) . '

');}
$vocab = taxonomy_vocabulary_machine_name_load($vocab['vocabulary']);

as suggested in #16, I got following:

• array | tags
• array | migrate_example_beer_styles
• array |
• array |
• array |
• array | dictionary
• array | forums
• array | book_size
• array | binding
• array | language
• array | nationalities
• array | book_category
• array | dictionary
• array | book_sale_period
• array | award_level
• array | award_category

• Notice: Undefined index: vocabulary in apachesolr_search_apachesolr_facets() (line 847 of C:\xampp\htdocs\drupal8\sites\all\modules\apachesolr\apachesolr_search.module).
• Notice: Undefined index: vocabulary in apachesolr_search_apachesolr_facets() (line 848 of C:\xampp\htdocs\drupal8\sites\all\modules\apachesolr\apachesolr_search.module).
• Notice: Trying to get property of non-object in apachesolr_search_apachesolr_facets() (line 850 of C:\xampp\htdocs\drupal8\sites\all\modules\apachesolr\apachesolr_search.module).
• Notice: Undefined index: vocabulary in apachesolr_search_apachesolr_facets() (line 847 of C:\xampp\htdocs\drupal8\sites\all\modules\apachesolr\apachesolr_search.module).
• Notice: Undefined index: vocabulary in apachesolr_search_apachesolr_facets() (line 848 of C:\xampp\htdocs\drupal8\sites\all\modules\apachesolr\apachesolr_search.module).
• Notice: Trying to get property of non-object in apachesolr_search_apachesolr_facets() (line 850 of C:\xampp\htdocs\drupal8\sites\all\modules\apachesolr\apachesolr_search.module).
• Notice: Undefined index: vocabulary in apachesolr_search_apachesolr_facets() (line 847 of C:\xampp\htdocs\drupal8\sites\all\modules\apachesolr\apachesolr_search.module).
• Notice: Undefined index: vocabulary in apachesolr_search_apachesolr_facets() (line 848 of C:\xampp\htdocs\drupal8\sites\all\modules\apachesolr\apachesolr_search.module).
• Notice: Trying to get property of non-object in apachesolr_search_apachesolr_facets() (line 850 of C:\xampp\htdocs\drupal8\sites\all\modules\apachesolr\apachesolr_search.module).

jpmckinney’s picture

Getting closer. Now, instead try:

        $vocab = array_shift($vocabs);
if (user_access('administer search') && empty($vocab['vocabulary'])) {
  drupal_set_message('<pre>' . print_r($vocab, TRUE) . '</pre>');
}
        $vocab = taxonomy_vocabulary_machine_name_load($vocab['vocabulary']);
pmorel’s picture

Having the same error, the vocabulary triggering the notice is 'field_tags' to me. This appears in the field_config table along side the 'taxonomy_forums'.

They both have type='taxonomy_term_reference' and module='taxonomy'. However, only the field_tags vocabulary cannot be loaded. Is field_tags really a vocabulary? A least It does not appear in the taxonomy_vocabulary table (whereas forums does)

Hope this helps towards resolving the issue.

pwolanin’s picture

Status: Postponed (maintainer needs more info) » Needs review
FileSize
758 bytes

This looks like some kind of screwiness with deleted fields or a bad core upgrade.

Here's a bit of a brute-force fix.

pwolanin’s picture

Status: Needs review » Active

committed the above patch - but worth someone looking for the deeper cause.

jpmckinney’s picture

Title: Trying to get property of non-object i » $vocab['vocabulary'] is sometimes empty
legendfall’s picture

In my case, with patch provided in #20, the Notice of "Trying to get property of non-object in apachesolr_search_apachesolr_facets() ..." is gone, but still remains following:

•Notice: Undefined index: vocabulary in apachesolr_search_apachesolr_facets() (line 845 of ...\sites\all\modules\apachesolr\apachesolr_search.module).

legendfall’s picture

Hi all, in order to find source of problem, I started a new installation of drupal 7 on another computer, and now located where this problem comes from.

1. Apache Solr Search works fine with required modules enabled, both indexing and searching just nice.
2. For importing external data to Drupal 7, I chose Migrate module and have it installed in my drupal, there are four pieces within this module: Migrate, Migrate Example, Migrate UI and recently added migrate-example-baseball. In beginning I enabled all four pieces, imported couple example data provided in Migrate Example and reindexed the Apache Solr,following notice was given:
•Notice: Undefined index: vocabulary in apachesolr_search_apachesolr_facets() (line 845 of ...\sites\all\modules\apachesolr\apachesolr_search.module).

then I uninstalled Migate Example and tried Solr search again, works fine again. then I tried to import data in migate-example-baseball using DRUSH command line, reindexed imported data and search in Drupal, its doing just good!

3. Now back to original computer and uninstall Migrate Example, search with Solr, warning message gone.

4. therefore I believe there is something wrong with Migrate Example of Migrate module.

ps:
system configuration:
windows 7
xampp
tomcat 7
apache solr 1.4.1
drupal 7 (drupal-7.x-dev, apachesolr-7.x-1.0-beta5,migrate-7.x-2.0)

pwolanin’s picture

all warranties are void if you try to run on Windows...

In any case, I don't see how your comment is related to this issue.

jpmckinney’s picture

Status: Active » Fixed

Code no longer exists due to shift to facetapi.

Status: Fixed » Closed (fixed)

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