# Job exception: UserDestroyer::PostsExistError

**URL:** https://meta.discourse.org/t/job-exception-userdestroyer-postsexisterror/68372
**Category:** Bug
**Created:** [2017年八月19日 13:36 UTC](https://meta.discourse.org/t/job-exception-userdestroyer-postsexisterror/68372 "2017-08-19T13:36:02Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![Pad\_Pors](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pad_pors/32/52016_2.png) [@Pad\_Pors](https://meta.discourse.org/u/Pad_Pors)
#### Post date: [2017年八月19日 13:36 UTC](https://meta.discourse.org/t/job-exception-userdestroyer-postsexisterror/68372/1 "2017-08-19T13:36:02Z")

</div>

I’m getting this error repeatedly after a recent update:

```plaintext
var/www/discourse/app/services/user_destroyer.rb:18:in `destroy'
/var/www/discourse/app/jobs/onceoff/fix_primary_emails_for_staged_users.rb:17:in `block (2 levels) in execute_onceoff'
/var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.9/lib/active_record/relation/delegation.rb:46:in `each'
/var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.9/lib/active_record/relation/delegation.rb:46:in `each'
/var/www/discourse/app/jobs/onceoff/fix_primary_emails_for_staged_users.rb:15:in `block in execute_onceoff'
/var/www/discourse/app/jobs/onceoff/fix_primary_emails_for_staged_users.rb:10:in `each_key'
/var/www/discourse/app/jobs/onceoff/fix_primary_emails_for_staged_users.rb:10:in `execute_onceoff'
/var/www/discourse/app/jobs/onceoff.rb:21:in `execute'
/var/www/discourse/app/jobs/base.rb:153:in `block (2 levels) in perform'

```

---

<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: [2017年八月21日 13:20 UTC](https://meta.discourse.org/t/job-exception-userdestroyer-postsexisterror/68372/2 "2017-08-21T13:20:15Z")

</div>

@LeoMcA any idea what this can be?

---

<div class="post-metadata">

### Author: ![LeoMcA](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leomca/32/87233_2.png) [@LeoMcA](https://meta.discourse.org/u/LeoMcA)
#### Post date: [2017年八月21日 14:16 UTC](https://meta.discourse.org/t/job-exception-userdestroyer-postsexisterror/68372/3 "2017-08-21T14:16:03Z")

</div>

@Pad_Pors do you have the full traceback - including the error being raised?

---

<div class="post-metadata">

### Author: ![LeoMcA](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leomca/32/87233_2.png) [@LeoMcA](https://meta.discourse.org/u/LeoMcA)
#### Post date: [2017年八月21日 14:29 UTC](https://meta.discourse.org/t/job-exception-userdestroyer-postsexisterror/68372/4 "2017-08-21T14:29:34Z")

</div>

nvm, I’ve figured it out - fix incoming

---

<div class="post-metadata">

### Author: ![LeoMcA](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leomca/32/87233_2.png) [@LeoMcA](https://meta.discourse.org/u/LeoMcA)
#### Post date: [2017年八月21日 14:50 UTC](https://meta.discourse.org/t/job-exception-userdestroyer-postsexisterror/68372/5 "2017-08-21T14:50:31Z")

</div>

[https://github.com/discourse/discourse/pull/5071](https://github.com/discourse/discourse/pull/5071)

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [2017年八月21日 23:07 UTC](https://meta.discourse.org/t/job-exception-userdestroyer-postsexisterror/68372/6 "2017-08-21T23:07:43Z")

</div>

> [@LeoMcA](#):
>
> I’ve figured it out - fix incoming

Did you manage to have a look at the state of @Pad_Pors’s DB? Otherwise, we’ll need the exact error message to be sure of what is going on.

---

<div class="post-metadata">

### Author: ![Pad\_Pors](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pad_pors/32/52016_2.png) [@Pad\_Pors](https://meta.discourse.org/u/Pad_Pors)
#### Post date: [2017年八月22日 04:55 UTC](https://meta.discourse.org/t/job-exception-userdestroyer-postsexisterror/68372/7 "2017-08-22T04:55:05Z")

</div>

@LeoMcA I didn’t get what I’m supposed to do. here is what I get in admin panel (but they are already there in the OP):

**info** :  
`Job exception: UserDestroyer::PostsExistError`

**backtrace** :

```plaintext
/var/www/discourse/app/services/user_destroyer.rb:18:in `destroy'
/var/www/discourse/app/jobs/onceoff/fix_primary_emails_for_staged_users.rb:17:in `block (2 levels) in execute_onceoff'
/var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.9/lib/active_record/relation/delegation.rb:46:in `each'
/var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.9/lib/active_record/relation/delegation.rb:46:in `each'
/var/www/discourse/app/jobs/onceoff/fix_primary_emails_for_staged_users.rb:15:in `block in execute_onceoff'
/var/www/discourse/app/jobs/onceoff/fix_primary_emails_for_staged_users.rb:10:in `each_key'
/var/www/discourse/app/jobs/onceoff/fix_primary_emails_for_staged_users.rb:10:in `execute_onceoff'
/var/www/discourse/app/jobs/onceoff.rb:21:in `execute'
/var/www/discourse/app/jobs/base.rb:153:in `block (2 levels) in perform'

```

**env** :

```process_id
application_version	[8f795b35bb18cebb01e1853ce642d78262a3af64, 42c1b7e6e0ba4f0d5c38aaa939f3a63f9751f720]
current_db	default
current_hostname	padpors.com
job	Jobs::FixPrimaryEmailsForStagedUsers
problem_db	default
	
opts	
current_site_id	default

```

and the image:

 ![image](https://global.discourse-cdn.com/meta/original/3X/e/2/e25f45acde685a0b3852fca41e52a3b606054315.png)

---

<div class="post-metadata">

### Author: ![LeoMcA](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leomca/32/87233_2.png) [@LeoMcA](https://meta.discourse.org/u/LeoMcA)
#### Post date: [2017年八月22日 07:33 UTC](https://meta.discourse.org/t/job-exception-userdestroyer-postsexisterror/68372/8 "2017-08-22T07:33:15Z")

</div>

> [@tgxworld](#):
>
> Did you manage to have a look at the state of @Pad_Pors’s DB?

No, but I did manage to reproduce the backtrace exactly, and the exception also matches:

> [@Pad\_Pors](#):
>
> Job exception: UserDestroyer::PostsExistError

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [2017年八月22日 07:33 UTC](https://meta.discourse.org/t/job-exception-userdestroyer-postsexisterror/68372/9 "2017-08-22T07:33:53Z")

</div>

Can you provide me with the repro steps? Thank you 🙂

---

<div class="post-metadata">

### Author: ![LeoMcA](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leomca/32/87233_2.png) [@LeoMcA](https://meta.discourse.org/u/LeoMcA)
#### Post date: [2017年八月22日 07:46 UTC](https://meta.discourse.org/t/job-exception-userdestroyer-postsexisterror/68372/10 "2017-08-22T07:46:16Z")

</div>

Uuuh, sort-of. I did it using an rspec test - so repro steps would be:

```
git remote add LeoMcA https://github.com/LeoMcA/discourse.git
git fetch LeoMcA remove_duplicated_without_posts
git checkout LeoMcA/remove_duplicated_without_posts -- spec/jobs/fix_primary_emails_for_staged_users_spec.rb
RAILS_ENV=test bundle exec rspec spec/jobs/fix_primary_emails_for_staged_users_spec.rb

```

Which should produce the output:

```
F.

Failures:

  1) Jobs::FixPrimaryEmailsForStagedUsers should keep the duplicated staged user with posts
     Failure/Error: raise PostsExistError if !opts[:delete_posts] && user.posts.count != 0
     
     UserDestroyer::PostsExistError:
       UserDestroyer::PostsExistError
     # ./app/services/user_destroyer.rb:18:in `destroy'
     # ./app/jobs/onceoff/fix_primary_emails_for_staged_users.rb:17:in `block (2 levels) in execute_onceoff'
     # ./app/jobs/onceoff/fix_primary_emails_for_staged_users.rb:15:in `block in execute_onceoff'
     # ./app/jobs/onceoff/fix_primary_emails_for_staged_users.rb:10:in `each_key'
     # ./app/jobs/onceoff/fix_primary_emails_for_staged_users.rb:10:in `execute_onceoff'
     # ./spec/jobs/fix_primary_emails_for_staged_users_spec.rb:29:in `block (3 levels) in <top (required)>'
     # ./spec/jobs/fix_primary_emails_for_staged_users_spec.rb:29:in `block (2 levels) in <top (required)>'

Finished in 2.26 seconds (files took 1.98 seconds to load)
2 examples, 1 failure

Failed examples:

rspec ./spec/jobs/fix_primary_emails_for_staged_users_spec.rb:26 # Jobs::FixPrimaryEmailsForStagedUsers should keep the duplicated staged user with posts

```

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [2017年八月22日 07:48 UTC](https://meta.discourse.org/t/job-exception-userdestroyer-postsexisterror/68372/11 "2017-08-22T07:48:21Z")

</div>

OK in that case, we need to transfer all existing posts on the duplicated user to the only user that we’re keeping.

---

<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: [2017年八月23日 01:00 UTC](https://meta.discourse.org/t/job-exception-userdestroyer-postsexisterror/68372/12 "2017-08-23T01:00:05Z")

</div>

This topic was automatically closed after 31 hours. New replies are no longer allowed.
