Previewed Badges not Awarding

AI-generated summary

In a support discussion regarding badges not being awarded, Umbrella reported that while the “preview granted badges” feature displays users correctly, the actual badge granting process fails despite daily updates being enabled. sam suggested manually triggering the Jobs::BadgeGrant task via the Sidekiq scheduler and checking logs for errors. Umbrella shared a database error indicating a duplicate key violation on the user_badges table. Upon reviewing the error, sam identified the root cause: badge 104 was missing the “Query targets posts” setting. Umbrella confirmed that enabling this option resolved the issue, and the badges are now awarding correctly.

The badge system has been a big hit on our forums, but I’ve encountered a small issue. I’ll admit, I’m not the most savvy and my permissions for the forums end forum-side as an administrator.

There are a couple of badges that I can “preview granted badges” perfectly well (and it shows a healthy list of users) but it doesn’t award those badges. I also made sure I had update daily selected! My guess is that the query is snagging somewhere, but everything I’ve learned is from Discourse meta! I’ve tried to read up on other issues on Discourse meta, but none of them seem to solve my problem (or they do and I’m failing to interpret that they’re the solution :stuck_out_tongue:)

When you go to SITENAME/sidekiq/scheduler you can kick off the daily task, Jobs::BadgeGrant

Kick it off, wait till it finishes, then go to SITENAME/logs to see if you have any errors.

Thanks for the timely response! :slight_smile:

Here's the error I have! Job exception: PG::Error: ERROR: duplicate key value violates unique constraint "index_user_badges_on_badge_id_and_user_id_and_seq" DETAIL: Key (badge_id, user_id, seq)=(104, 224, 0) already exists. : INSERT INTO user_badges(badge_id, user_id, granted_at, granted_by_id, post_id) SELECT 104, q.user_id, q.granted_at, -1, NULL FROM ( SELECT p.user_id, p.id post_id, p.updated_at granted_at FROM badge_posts p WHERE p.post_number > 1 AND p.like_count >= 5 AND ('t' OR p.id IN (-2) ) ) q LEFT JOIN user_badges ub ON ub.badge_id = 104 AND ub.user_id = q.user_id
        WHERE (ub.badge_id IS NULL AND q.user_id <> -1)
        RETURNING id, user_id, granted_at</details>

Looks to me like you forgot to tick “Query targets posts” on badge 104

You’re absolutely right, thank you so much, everything is working wonderfully now! :smiley: