Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Getting following notice:
Notice: Trying to get property of non-object in hs_taxonomy_hierarchical_select_valid_item() (line 588 of /www/sites/all/modules/contrib/hierarchical_select/modules/hs_taxonomy.module).
Btw this bug seems to be popular on the Google - search gives me 52 results of Drupal sites with this bug indexed: http://www.google.cz/search?gcx=w&q=Notice%3A+Trying+to+get+property+of+...()
Comment | File | Size | Author |
---|---|---|---|
#4 | null_term_load_check-1331812-4.patch | 3.31 KB | jweowu |
#2 | 1331812-2_Notice_in_hs_taxonomy_hierarchical_select_valid_item.patch | 1 KB | wojtha |
Comments
Comment #1
skizzo CreditAttribution: skizzo commentedSeeing the same error, quite likely in a different context. I have few vocabularies term-referenced in user account. Users pick terms in user profile via hierarchical_select, profiles are displayed ok and everything works nicely. As soon as I enable domain_taxonomy I get this error when displaying a user profile. If I disable domain_taxonomy the error goes away.
Comment #2
wojtha CreditAttribution: wojtha commentedThe line 588 doesn't match, but only lines where this notice could be raised are attempts to read $term properties. So I added check if the term is really loaded.
Comment #3
skizzo CreditAttribution: skizzo commentedI do not see the error any more after applying the patch.
Comment #4
jweowu CreditAttribution: jweowu commentedThis appears to be just one of several instances in hs_taxonomy.module where the return value of taxonomy_term_load() is not checked.
I've looked at all of those calls, and made what seem like the appropriate changes (along with a fix for the related error mentioned below); however I'm not familiar with this code, so someone definitely needs to review it.
The change I'm mostly unsure about is in hs_taxonomy_hierarchical_select_item_get_label(), where I'm now returning the string "<invalid>" for the term label, but I'm not really certain how (or if) it's going to be used.
For searchability, along with the error detailed above, I had also been seeing the following when a term no longer existed. This code wasn't loading the term itself, but the tid which was causing the error was one which no longer existed. The patch addresses this as well.
Comment #5
firebird CreditAttribution: firebird commentedWorks for me.
Comment #6
wojtha CreditAttribution: wojtha commented@firebird ... so ... RTBC?
Comment #7
skizzo CreditAttribution: skizzo commentedpatch in #4 works for me, fixing the "Undefined index: hs_lineages in hs_taxonomy_field_formatter_view() (line 402 of [...] hs_taxonomy.module)" error. I am not changing status to RTBC, as I have not much insight into software development.
Comment #8
firebird CreditAttribution: firebird commentedI've been using the patch for a while and haven't seen any problems, so RTBC.
Comment #9
jweowu CreditAttribution: jweowu commentedfirebird: Are you sure about that?
Comment #10
firebird CreditAttribution: firebird commentedAfter re-reading the RTBC requirements, here's a more verbose "Works for me":
I do consider myself "an experienced developer". The patch has been in use in a largish actively developed project with five developers working on it, and no-one has noticed any side-effects with it.
I've gone through the code changes, and it looks like there are just new checks against missing or empty values, and changes in indentation. The one other change you were unsure about just returns a string to the UI level; I don't see any potential problems with that either.
That said, the dropbox functionality isn't actually in use in our project, so it might be better to hold off until someone who is using it reviews the patch as well. Back to "Needs Review".
Comment #11
jefkin CreditAttribution: jefkin commentedI've been using this dropbox in development and finally got annoyed at the warnings I was seeing spewing all over the site. I spent 2 minutes and hacked a quicky solution:
using '@' on line 402
and using a fail safe check on line 588
for the original bug error.
This worked fine, solving the problem perfectly to the satisfaction of my team and my client. Then I was going to post a patch for the changes so I searched here and found this issue. My patches and those proposed are technically the same, but the ones in #2 and #4 are both far cleaner and clearer, so I unwound my changes and applied the patches, and asked my team and client to review again, we give #2 and #4 a pass.
:D We're not the full community, but my vote is RTBC.
Comment #12
jweowu CreditAttribution: jweowu commentedIf someone could please review the usage of
hs_taxonomy_hierarchical_select_item_get_label()
and confirm that the change to that is going to be sane, RTBC would be appropriate.By default it's only called by
hs_taxonomy_views_hierarchical_select_item_get_label()
which is implementinghook_hierarchical_select_item_get_label()
, which is invoked in_hierarchical_select_dropbox_generate()
.$item
would be a term id, as it is passed totaxonomy_load_term()
edit:
In fact, I think that code never gets executed.
_hierarchical_select_dropbox_generate()
invokeshook_hierarchical_select_valid_item
to clean the$selection
array. That callshs_taxonomy_hierarchical_select_valid_item()
which should filter out invalid terms, and that array is the source of the data which is passed tohs_taxonomy_hierarchical_select_item_get_label()
Confirmation?
(I'd still keep the change, but it would no longer be a hindrance to getting this patch committed.)
Comment #13
AaronELBorg CreditAttribution: AaronELBorg commentedI've been using the 'Feeds Tamper' plugin (with Feeds, of course) to match on multiple terms which uses hierarchical select.
I've ran into this error message today when trying to insert terms that are numbers using a CSV import (via Feeds).
The vocab ("Coupon Type") looks like this:
-% Off
--5
--10
--15
I'm getting the '% Off' part but I'm not setting any of the children. In fact, they're getting inserted into the db as their respective value as opposed to their tid.
If I change the vocab to look like this:
-% Off
--five
--ten
--fifteen
.....it works.
I've posted this issue in both the feeds tamper module and this one. Thanks for any advice.
Comment #14
jweowu CreditAttribution: jweowu commentedAaronELBorg: By "this error message", are you referring to the subject of this issue?
And if so, have you actually tried this patch?
I'm unsure whether the remainder of your comment is related to this issue. You might also like to link to your duplicate issue, rather than just saying that you've done that.
Comment #15
AaronELBorg CreditAttribution: AaronELBorg commentedYes, the error message in question is indeed the subject of this issue.
I tried #2 and although that stopped the error from being displayed it didn't fix the issue I'm having with numbers in the vocab. Haven't tried #4 yet.
Here's a link to my issue in the Feeds Tamper project:
http://drupal.org/node/1441750
Thanks for the reply.
Comment #16
jweowu CreditAttribution: jweowu commented#4 is a more comprehensive version of #2, so I would suggest using that one.
It doesn't sound like your problem with numeric terms is related to this issue.
Comment #17
AaronELBorg CreditAttribution: AaronELBorg commentedYou're correct, jweowu.
The issue was with Feeds and patched here:
http://drupal.org/node/1426762#comment-5612248
Thanks again.
Comment #18
klaasvw CreditAttribution: klaasvw commentedThe patch in #4 also solved the issue for me. The change to hs_taxonomy_hierarchical_select_item_get_label() looks fine to me. I'm not entirely sure if this case will ever pop up but it can't hurt to have a fallback when a term doesn't exist.
So considering the above and that this solved the issue for other people I'm marking this RTBC.
Comment #19
visabhishek CreditAttribution: visabhishek commentedPatch working for me..
Thanks !!
Comment #20
francoud CreditAttribution: francoud commentedthe simple patch in#11 worked for me. But i had to combine it with another patch:
http://drupal.org/node/1324070 - because i had both the errors. Now worked. "both" the patch should, imho, committed... thanks to all! :)
Comment #21
msamavi CreditAttribution: msamavi commentedThanks jefkin @#11
Comment #22
jweowu CreditAttribution: jweowu commentedfrancoud, msamavi: #4 is the current RTBC version of the patch for this issue.
Comment #23
Wim LeersCommitted (http://drupalcode.org/project/hierarchical_select.git/commit/22acf869782...) #4 with the exception of:
That's never been necessary in the past, so it shouldn't be necessary now.
Thanks! And sorry for taking so long…
Comment #25
venkirs CreditAttribution: venkirs commentedhow to relate two different vocabulary in with term ... if you have any suggestion give