1. I set "Fivestar comment settings" to "disabled".

2. I vote on a story node

3. I post a new comment on this node

==> The vote is lost


I'm new to drupal but I think it is because:

file: fivestar_comment.inc
function: fivestar_comment_delete($cid, $nid, $uid)

Those line:

  $new_vote = db_result(db_query('SELECT value FROM {fivestar_comment} fc INNER JOIN {comments} c ON fc.cid = c.cid WHERE c.uid = %d AND c.nid = %d ORDER BY timestamp desc', $uid, $nid)); 
  _fivestar_cast_vote('comment', $nid, empty($new_vote) ? 0 : $new_vote, 'vote', $uid);

Will delete a user's vote if the user has voted on the story using the standard node voting system, not using the comment voting system (the user voted on the node itself, not while posting a comment). Therefore the user has no row in the fivestar_comment table, db_result() then returns false and _fivestar_cast_vote() will erase the user vote for the node ("0" is passed).

Is it possible?


Fast and ugly workaround:

put a


At the beginning of the fivestar_comment_delete() function and be sure to stick to "disabled" for option "Fivestar comment settings".


Thanks for your nice module!


Members fund testing for the Drupal project. Drupal Association Learn more


tata668’s picture

Title: Lost a node vote when a comment is submitting with option "Fivestar comment settings" set to "disabled" » Lost a node vote when a comment is submitted with option "Fivestar comment settings" set to "disabled"

Typo, sorry for my bad english (submitting = submitted)

captcha’s picture

For me this happens when Fivestar comments is set to 'Optional Rating' not 'Disabled' and a rating is not submitted along with the comment.
This happens when I am logged in as admin, and I comment on a node previously rated by me.
And now, this makes sense:

tata668’s picture

I guess you are right, it could also append with the "optional" option, as long as no vote is posted when commenting.

The "optional" option would be a little more difficult to fix I think, but the "disabled" option should be easier.

The question is why would the fivestar_comment_delete() function be called in the first place, even if "disabled" is selected?
It is called from:

function fivestar_comment_set($comment)

because of line:

if ($comment->fivestar_rating)

is undefined. As I said, I'm new to Drupal so I'm not sure exactly how this could be achieved, but I think everything in this function should be skipped if the comment voting is disabled:



Or, maybe the fivestar_comment.inc shouldn't be used at all if the "disabled" option is selected? I tried to delete the file, but some of its functions are called from fivestar.module and it generates errors.

neopoet’s picture

Thanks #3. The fix worked.

I agree- there should be a switch around line 150 (fivestar_comment.inc) to see if the form is set to disabled or not.

softtouch’s picture

Did not fix for me.
I added the #3 and still, the rating will be set to none after posting a comment.

tata668’s picture

#3 is not a fix, It's pseudo-code. "FIVESTAR_COMMENT_IS_ENABLED" doesn't actually exist.

Adding a "return;" as the very first line of the "fivestar_comment_delete()" function is a real fix (but it's ugly and only works with "Fivestar comment settings" set to "disabled").

captcha’s picture

After wondering why I wasn't losing the vote on rating 'disabled', I discovered that this was happening only for one node. Other nodes were losing their votes on comment posting. Then, I looked at the code and found that a previous comment rating would be used, when available, and this explained the votes not lost for some nodes while lost in others [code in fivestar_comment_delete() ].

I agree that the call to fivestar_comment_delete() in fivestar_comment_set() is a bit odd, as that seems to follow from an insert/update operation.

function fivestar_comment(&$comment, $op) {
    case 'insert':
    case 'update':
      // Why comments are arrays here... only comment.module knows.

Preloading the comment rating will solve the issue for the Optional Rating and is intuitive, a fix will still be required for Disabled rating, though.
I am not sure, but a few changes in fivestar_comment_set() could perhaps take care of this.

Personally, if one is allowing rating on nodes and comments are enabled then, it would be a rare case to disable rating while commenting. But there can be a case where ratings are permitted for a time period and then when that period lapses voting is disabled while commenting is allowed to continue.

Actually, this could be a neat feature in a later release - time-based voting - voting could be automatically disabled after a time setting.

Eugene Fidelin’s picture

I have the same trouble, so where is the patch or new version of module?

softtouch’s picture

I surrendered. I lost all my votes by commenting on posts.
I changed to nodevote, which is not as nice as this, but it works, and only that counts.

scb’s picture

This should fix the problem in the case that comment voting is disabled. Don't know in other cases.
This is a quick and dirty fix, though.
This is the same solution as #3 but with real code...

function fivestar_comment_delete($cid, $nid, $uid) {
  //If fivestar_comment is disabled for this node type, return doing nothing
  $node = node_load($nid); //Maybe there is a lighter way of obtaining the node type...
  if (!variable_get('fivestar_comment_'.$node->type , false)) return;


I think if fivestar_comment is disabled this function should not be called at all... so this is just a quick fix

quicksketch’s picture

Status: Active » Fixed
5.36 KB
5.38 KB

Sorry fellas I went on vacation for 2 weeks. I had a fix ready but I was stuck in indecision about what to do for the Optional vote case. I finally came up with what I think is the most logical solution:

- If a user submits a review with a rating, it sets the node vote.
- If a user submits a second review with a different rating, it sets a new node vote but leaves the previous review rating the same.
- If a user submits a second review without a rating, no changes are made to the node vote.
- If a user edits their first review (that had a rating) and sets the rating to none, their node vote is canceled.
- Deleting a review that has a rating will cancel their node vote, unless they've submitted multiple reviews in which case the value of a previous review will be their new node vote.

Of course I also fixed the bug where editing a node would delete the vote entirely. Please try out the latest 1.x development version or apply this patch. If the problem still exists, please reopen.

softtouch’s picture

Latest version 1.1.1-beta3 did not include the patch...
Where is the dev version you mention?

quicksketch’s picture

You can either checkout from CVS to get the "bleeding edge" or grab from the development version page.

http://drupal.org/project/fivestar (Click on View all Releases) =>
http://drupal.org/node/103123/release (Scroll down to 5.x Development version) =>
http://drupal.org/node/192517 (download it here).

I don't list the development version on the Fivestar frontpage because generally the 5.x development version is broken in some way. Because we're trying to stabilize 1.10 for release though, it's the most stable. After this patch gets checked I'll release 1.10 beta 4. Hopefully releasing 1.10 final if we don't find any new problems.

captcha’s picture

Status: Fixed » Active

This really was a trouble-maker.
Things are looking fine, haven't done a thorough test.
The only odd thing that happened when I tried out the dev version was that with Comment widget > Optional rating, the comment didn't get posted, the rating was updated, though!
Cannot reproduce this anymore, after I deleted my node vote and all reviews and began afresh.

Hope you had a nice holiday, you are back with a bang :)

captcha’s picture

Status: Active » Fixed

Had changed the status when I noticed that comments were missing.
Cannot reproduce now, so changing it back to fixed.

Thanks for the work on this.

OFF’s picture

Status: Fixed » Active

This problem is steal alive for unregistered users.

When the user adds the comment node receives a double estimation which is kept after removal of the comment.

Help, please, fivestar the unique module allowing to realize a rating site on which it is not obligatory to be registered.

quicksketch’s picture

Status: Active » Fixed

OFF, thanks for finding this bug. I confirmed it was a problem for anonymous users still because we didn't have a way of tracking down the original vote for anonymous reviews. I've added another column to the fivestar_comment table so that we can keep track of this vote_id, even for anonymous users. Please try out the latest development version or CVS (be sure to run update.php) and let me know if the problem still exists for anonymous users.

OFF’s picture

Big thanks!!

I have been updated for stable version (5.x-1.11)

Has fluently tested the site, at present problems it is not visible.


softtouch’s picture

So you mean, I can finally use ratings for comments with the 5.x-1.11 without being scared that all my votes are gone?

quicksketch’s picture

Thanks for the followup OFF.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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