# Previewed Badges not Awarding

**URL:** <https://meta.discourse.org/t/previewed-badges-not-awarding/32896>\
**Category:** Product Support\
**Tags:** badges\
**Created:** [September 4, 2015, 12:45am UTC](https://meta.discourse.org/t/previewed-badges-not-awarding/32896 "2015-09-04T00:45:49Z")\
**Posts on this page:** 6\
**Page:** 1

## AI-generated summary

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

<div class="post-metadata">

**Author:** ![Umbrella](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/umbrella/32/116583_2.png) [@Umbrella](https://meta.discourse.org/u/Umbrella)\
**Post date:** [September 4, 2015, 12:45am UTC](https://meta.discourse.org/t/previewed-badges-not-awarding/32896/1 "2015-09-04T00:45:49Z")

</div>

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 😛)

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [September 4, 2015, 3:30am UTC](https://meta.discourse.org/t/previewed-badges-not-awarding/32896/2 "2015-09-04T03:30:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Umbrella](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/umbrella/32/116583_2.png) [@Umbrella](https://meta.discourse.org/u/Umbrella)\
**Post date:** [September 4, 2015, 7:23am UTC](https://meta.discourse.org/t/previewed-badges-not-awarding/32896/3 "2015-09-04T07:23:06Z")

</div>

Thanks for the timely response! 🙂

> **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>
> 
> ```

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [September 4, 2015, 7:34am UTC](https://meta.discourse.org/t/previewed-badges-not-awarding/32896/4 "2015-09-04T07:34:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Umbrella](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/umbrella/32/116583_2.png) [@Umbrella](https://meta.discourse.org/u/Umbrella)\
**Post date:** [September 4, 2015, 5:49pm UTC](https://meta.discourse.org/t/previewed-badges-not-awarding/32896/5 "2015-09-04T17:49:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)\
**Post date:** [September 4, 2015, 9:27pm UTC](https://meta.discourse.org/t/previewed-badges-not-awarding/32896/6 "2015-09-04T21:27:14Z")

</div>

Closed on September 4, 2015, 9:27pm UTC


