I was finally able to resolve the issue. I don’t know why it was happening, but I favorited another badge then unfavorited the Hot Link badge and the problem was gone (didn’t fix it before)
This only occurs when you have a stacked badge favourited. In my case, I have 2 Great Topic badges and 4 Good Topic badges, for a total of “6” badges favourited. I can’t toggle anything. Singular badges seem to be fine.
I cannot reproduce this on Discourse Meta, no. I just logged in, went to the badges section, and attempted to favorite 2 badges. It worked perfectly for me.
This was flagged on Meta in 2021, but I don’t think it’s quite the same issue. The error message is the same generic “FAILED” but the reproduction steps aren’t the same.
However, I do think we’re missing a crucial thing here. Looking at all the people reporting the issues, they all have favorited stacked badges. Yet, @vscplays was unable to favorite and unfavorite them just fine.
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.
Edit:
Based on the generator tag, the version of Discourse on the devforum is v3.0.3, which means the underlying code that handles badge favoriting is this:
can_favorite_badge? for brevity returns a failure if the badge doesn’t belong to the current user or if the badge ID is 1-4, which are badges relating to trust levels. I highly doubt it’s this.
Next failure condition is
if !user_badge.is_favorite &&
user_badges.select(:badge_id).distinct.where(is_favorite: true).count >=
SiteSetting.max_favorite_badges
return render json: failed_json, status: 400
end
We can already eliminate this since the badge is already favorited, but even then this shouldn’t be the issue because the badge_id from my understanding isn’t unique (hence the distinct call), it’s the same between every instance of a stacked badge.
These are the only two error cases that return that specific FAILED message in this route. As far as I’m aware, if the controller itself was failing, it should’ve returned an internal server error, not a bad request, so I don’t really understand what else could be failing here.
Also, in my search through the codebase and some googling, I found what appears to be the exact issue on Meta, but it wasn’t ever resolved:
In their screenshot you can clearly see the badges are stacked and they’re already favorited, so I do think this is the issue.
Thanks for going through this effort! Yeah this is a tough one, since it occurs in Discourse code base which we don’t directly control. In the past when we had to work with Discourse for code fixes it was a significant burden and roundtrip time to get things merged and waiting for a new version to be pushed.
I definitely recommend bumping the meta thread and/or if you know the code fix to make, you could pre-empt it and let the Discourse team know, maybe they can pull in the change so we can consume it eventually. Unfortunately since it lives in Discourse code and given the other 100 things we’re always working on at the same time, I can’t really promise we would have time for this any time soon.
As a former Discourse sysadmin, yeah. This sucks massively. It’s good forum software but it’s a pain to get anything fixed and pushed in a reasonable timeframe. Ended up moving to Flarum because of it, although not sure of the development status on that one.
I have bumped meta already so it’s just playing the waiting game. Honestly it could also be related to the fact we’re on a version of Discourse that’s about a year or two old now so they might not even be willing to support it beyond “upgrade to latest”.
I like Ruby but not nearly that much, plus the issues mentioned above mean it might take ages before such a fix gets deployed. Would love to do it for anything else given the opportunity though.
And yeah that’s totally understandable. I’m sure the forum software having a bug like “can’t unfavorite a badge” is extremely minor in comparison. Take your time!
Paste and run this in your browser’s console on the badges page and it will unfavorite all badges. The bug may happen again if you favorite a badge that you have multiple of, but atleast you can favorite other badges again