Discourse 게임화 - /leaderboard 경로에서 404 / MissingAttributeError 발생

So, I recently decided to enable gamification and immediately ran into an issue where the /leaderboard route was returning a 404 error. The backend had over 800k score records calculated and the permissions checked out, but the page itself wouldn’t load.

Checking the server logs showed:
ActiveModel::MissingAttributeError (missing attribute 'admin' for User)

While digging through the plugin code, I noticed in lib/discourse_gamification/leaderboard_cached_view.rb that the user query uses a specific .select string to pull columns for the leaderboard:

.select(
"users.id, users.name, users.username, users.uploaded_avatar_id, p.total_score, p.position",
)

Because users.admin and users.moderator aren’t included in that query, the instantiated user objects don’t have those fields available. It looks like (?) somewhere further down the line during serialization or core layout rendering, a staff check is being triggered on those users, causing Rails to throw the MissingAttributeError and fall back to a 404.

I manually edited that file to include users.admin and users.moderator in the .select block:

.select(
  "users.id, users.name, users.username, users.uploaded_avatar_id, users.admin, users.moderator, p.total_score, p.position",
)

After restarting the app container, the leaderboard started loading perfectly.

I’m guessing this is a bug (?) or have I completely overthought/overlooked something?

The site is currently on v2026.6.0-latest (47a830330f)

2개의 좋아요

보여 주신 에러와 설명은 일치합니다. 불행히도 47a830330f 또는 main에서 해당 문제를 재현할 수 없었습니다. 관리자 계정으로 로그인하여 시도해 보았고 일반 사용자로도 시도해 보았는데, 둘 다 정상적으로 로드되었습니다.

확인 차, 현재 Discourse 코어에 번들된 버전의 gamification을 사용 중이시며, 구버전의 독립형 플러그인은 설치되어 있지 않은지 확인 부탁드립니다.

MissingAttributeError가 발생하는 지점에 대한 스택 트레이스를 더 자세히 제공해 주실 수 있으신가요?

1개의 좋아요

@ted,

실제로는 이 메시지를 무시하셔도 됩니다. 결국 문제를 UserScoreSerializer에 연결된 플러그인으로 추적했습니다. 해당 플러그인은 자체적으로 좁은 범위의 .select() 문장을 구현하고 있었습니다. /logsMissingAttributeError에 대한 백트레이스가 제공되지 않아 처음에는 파악하기 어려웠습니다. rails를 통해 수동으로 호출하여 전체 스택 트레이스를 얻은 후에야 해당 문제를 일으킨 플러그인을 정확히 파악할 수 있었습니다.

도와주셔서 감사합니다. 그리고 오보로 인해 죄송합니다!

2개의 좋아요

괜찮습니다! 문제가 있으셨으니 올려주신 거고, 해결되어서 기쁩니다. :slightly_smiling_face: