# Side effects with system\_user monkey patch?

**URL:** https://meta.discourse.org/t/side-effects-with-system-user-monkey-patch/106470
**Category:** Development
**Created:** [January 14, 2019, 5:49am UTC](https://meta.discourse.org/t/side-effects-with-system-user-monkey-patch/106470 "2019-01-14T05:49:47Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![JeffsGlue2008](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jeffsglue2008/32/128359_2.png) [@JeffsGlue2008](https://meta.discourse.org/u/JeffsGlue2008)
#### Post date: [January 14, 2019, 5:49am UTC](https://meta.discourse.org/t/side-effects-with-system-user-monkey-patch/106470/1 "2019-01-14T05:49:47Z")

</div>

My team would like a plugin where the system user is a random person from our PR team, as users respond better to real people than robots (even if it’s made obvious that it’s an automated action/message!)

In response, I wrote this code in a plugin:

```plaintext
Discourse.module_eval do
	def self.pr_member
		Group.find_by(name: "PRTeam").users.sample
	end

	def self.system_user
		self.pr_member
	end

	def self.site_contact_user
		self.pr_member
	end
end

```

This seems to work fine, but are there any side effects I should be aware of for this? Is there a better way?

---

<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: [January 14, 2019, 9:23am UTC](https://meta.discourse.org/t/side-effects-with-system-user-monkey-patch/106470/2 "2019-01-14T09:23:17Z")

</div>

You can set many (most?) messages to come from a regular user in the site settings, so I’m not sure why this would be necessary?

---

<div class="post-metadata">

### Author: ![JeffsGlue2008](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jeffsglue2008/32/128359_2.png) [@JeffsGlue2008](https://meta.discourse.org/u/JeffsGlue2008)
#### Post date: [January 14, 2019, 2:01pm UTC](https://meta.discourse.org/t/side-effects-with-system-user-monkey-patch/106470/3 "2019-01-14T14:01:39Z")

</div>

That’s one–we’d like a group.

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [January 14, 2019, 3:48pm UTC](https://meta.discourse.org/t/side-effects-with-system-user-monkey-patch/106470/4 "2019-01-14T15:48:20Z")

</div>

> [@JeffsGlue2008](#):
>
> we’d like a group.

You mean a _random_ user from a group? It might be a better idea to update the `site contact username` from within a plugin. You could create a background job that assigns a random member of the group if you wish.

> [@JeffsGlue2008](#):
>
> are there any side effects I should be aware of for this?

Most likely. The system user is used all over the place. Returning a different, _random_ user every time `Discourse.system_user` is called might lead to _random_ problems. Also, Discourse often assumes that the system user has -1 as ID (`Discourse.SYSTEM_USER_ID` isn’t always used) and non-human users (ID \< 0) are often excluded in SQL queries, etc. None of that will work anymore, so’ll have to live with the consequences.

In short: Don’t do it or you might break Discourse in unforeseen ways.

---

<div class="post-metadata">

### Author: ![JeffsGlue2008](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jeffsglue2008/32/128359_2.png) [@JeffsGlue2008](https://meta.discourse.org/u/JeffsGlue2008)
#### Post date: [January 14, 2019, 3:49pm UTC](https://meta.discourse.org/t/side-effects-with-system-user-monkey-patch/106470/5 "2019-01-14T15:49:23Z")

</div>

> [@gerhard](#):
>
> It might be a better idea to update the `site contact username` from within a plugin. You could create a background job that assigns a random member of the group if you wish.

This sounds like a better solution to my problem. Where is the site contact username used?

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [January 14, 2019, 3:55pm UTC](https://meta.discourse.org/t/side-effects-with-system-user-monkey-patch/106470/6 "2019-01-14T15:55:56Z")

</div>

It’s used every time a system message is sent.

> <https://github.com/discourse/discourse/blob/main/lib/system_message.rb>
