# 部分用户在加载摘要页面时出现 500 错误（beta4）

**URL:** https://meta.discourse.org/t/500-error-loading-summary-page-for-some-users-beta4/101796
**Category:** Support
**Created:** [2018年十一月11日 19:56 UTC](https://meta.discourse.org/t/500-error-loading-summary-page-for-some-users-beta4/101796 "2018-11-11T19:56:28Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![DiscourseMetrics](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/discoursemetrics/32/55756_2.png) [@DiscourseMetrics](https://meta.discourse.org/u/DiscourseMetrics)
#### Post date: [2018年十一月11日 19:56 UTC](https://meta.discourse.org/t/500-error-loading-summary-page-for-some-users-beta4/101796/1 "2018-11-11T19:56:28Z")

</div>

I’m seeing a 500 error loading some users’ summary pages:

```
NoMethodError (undefined method `attributes' for nil:NilClass) /var/www/discourse/app/models/user_summary.rb:196:in `block in user_counts'

```

and

```
/var/www/discourse/app/models/user_summary.rb:196:in `block in user_counts'
/var/www/discourse/app/models/user_summary.rb:194:in `map'
/var/www/discourse/app/models/user_summary.rb:194:in `user_counts'
/var/www/discourse/app/models/user_summary.rb:80:in `most_liked_users'
/var/www/discourse/vendor/bundle/ruby/2.5.0/gems/active_model_serializers- 
0.8.4/lib/active_model/serializer.rb:122:in `block (2 levels) in associate'
...

```

I haven’t been able to ascertain if there are commonalities between the user profiles this happens to, but perhaps it has to do with which users are most liked by that user.

Happy to get any ideas on how to fix this 🙂

Cheers!

---

<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: [2018年十一月12日 06:39 UTC](https://meta.discourse.org/t/500-error-loading-summary-page-for-some-users-beta4/101796/2 "2018-11-12T06:39:20Z")

</div>

Hmmm I am torn on fixing this @eviltrout

> <https://github.com/discourse/discourse/blob/d1684a165259b8426b4e84d2099281023d76d908/app/models/user_summary.rb#L190-L199>

This repros the issue:

```ruby
  it "is robust enough to handle bad data" do
    UserActionCreator.enable

    liked_post = create_post
    user = Fabricate(:user)
    PostAction.act(user, liked_post, PostActionType.types[:like])

    users = UserSummary.new(user, Guardian.new).most_liked_users

    expect(users.map(&:id)).to eq([liked_post.user_id])

    # really we should not be corrupting stuff like this
    # but in production dbs this can happens sometimes I guess
    liked_post.user.delete

    users = UserSummary.new(user, Guardian.new).most_liked_users
    expect(users).to eq([])

  end

```

But you should not be doing `#delete` on users and leaving a mess around.

Simplest workaround is hunting for all the `acting_user_id` in `user_actions` table that do not have records in `users` table and nuking properly.

Since I have not seen this in our logs across 1000 sites I am somewhat reluctant to patch the code to allow for this corruption.

---

<div class="post-metadata">

### Author: ![JanJoost](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/janjoost/32/97173_2.png) [@JanJoost](https://meta.discourse.org/u/JanJoost)
#### Post date: [2018年十二月22日 16:59 UTC](https://meta.discourse.org/t/500-error-loading-summary-page-for-some-users-beta4/101796/4 "2018-12-22T16:59:41Z")

</div>

> [@sam](#):
>
> Since I have not seen this in our logs across 1000 sites I am somewhat reluctant to patch the code to allow for this corruption.

Hi @sam,

I am plagues by the same error. Is there anything I can do to offer you more insight?

---

<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: [2018年十二月24日 13:40 UTC](https://meta.discourse.org/t/500-error-loading-summary-page-for-some-users-beta4/101796/5 "2018-12-24T13:40:38Z")

</div>

OK I guess we hit the rule of 3 here… @vinothkannans can you fix the test case here:

> [@500 error loading summary page for some users (beta4)](https://meta.discourse.org/t/500-error-loading-summary-page-for-some-users-beta4/101796/2):
>
> Hmmm I am torn on fixing this @eviltrout This repros the issue: it "is robust enough to handle bad data" do UserActionCreator.enable liked\_post = create\_post user = Fabricate(:user) PostAction.act(user, liked\_post, PostActionType.types[:like]) users = UserSummary.new(user, Guardian.new).most\_liked\_users expect(users.map(&:id)).to eq([liked\_post.user\_id]) # really we should not be corrupting stuff like this # but in production dbs this can happens sometim…

Option 1.

Make our weekly job fix up internal data

Option 2.

Allow this thing to work even if internal data is a bit corrupt

* * *

I am tossing and turning between picking 1 or 2 … your call

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2018年十二月24日 19:30 UTC](https://meta.discourse.org/t/500-error-loading-summary-page-for-some-users-beta4/101796/7 "2018-12-24T19:30:06Z")

</div>

I recommend whatever is easiest.

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [2018年十二月24日 19:36 UTC](https://meta.discourse.org/t/500-error-loading-summary-page-for-some-users-beta4/101796/8 "2018-12-24T19:36:23Z")

</div>

> [@codinghorror](#):
>
> whatever is easiest

Then it’s done by the 2nd option 😉

[https://github.com/discourse/discourse/commit/a16bb32865af313e11e7799c8383bde8fdeab856](https://github.com/discourse/discourse/commit/a16bb32865af313e11e7799c8383bde8fdeab856)

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [2018年十二月29日 12:30 UTC](https://meta.discourse.org/t/500-error-loading-summary-page-for-some-users-beta4/101796/9 "2018-12-29T12:30:16Z")

</div>

This topic was automatically closed after 4 days. New replies are no longer allowed.
