Badge Favorites not working for some users - They get pop-up stating "FAILED"

I am having an issue with a user not being able to toggle their favorites. I found a few articles on here and pull requests that match this error, but they are two years old and the merge reqeusts were in place. So it seems to be another issue.

It is not every user, but this user has two favorites for their badges. Each badge has more then one accomplished. When I click on favorite it just shows a pop-up that says failed.

The concole in chrom states that we get a 400 error from our url /user_badges/17307/toggle_favorite.

Any ideas on how to fix this. It doesn’t work on the app or in the browser.

Similar Topic: "FAILED" error selecting Favorite badges

However the clicking twice did not work for this error.

Hi @Josiah_Philipsen :slight_smile:

Did you manage to get to the bottom of this in the end?

Might have a cause here. For reference, I’m a user on the Roblox DevForum running v3.0.3, not an admin, experiencing the issue described here. I did a mini writeup over there trying to work it out myself, but I’ll copy/paste the relevant part:

I was able to select my favorite badges a long time ago when I had individual ones, but now that I have stacked copies I can no longer unselect them, so maybe it’s due to getting more copies after you’ve favorited them, since each badge is unique no matter how many duplicates you get? That’s my current reasoning, but of course without being able to poke at the actual Discourse installation I can’t prove that.

I favorited the Great Topic and Good Topic badges a long time ago when I had singular copies, but I have now got 2 and 4 respectively. When I attempt to unfaovrite, it results in the generic FAILED response. Other users that haven’t favorited badges can favorite and unfavorite them at will, which indicates that this issue is caused by the addition of badges of the same type that are favorited already, and that those copies count towards your total favorites, therefore some assertion is failing.

Looking at toggle_favorite for this version, the only assertion relating to badge count is:

if !user_badge.is_favorite && true).count >=
  return render json: failed_json, status: 400

I initially dismissed this because user_badge.is_favorite should be true here, but now I’m starting to think that because of the extra copies they’re not considered favorited…

If this has been fixed by the way in a newer version, I apologise for resurrecting this, but the admins over there are trying to work it out and it’s been kind of a lost cause so I’m trying to get attention to it here to make it easier for them to fix it or upgrade Discourse.