Error: Patreon group membership callback failed for new user

I’m just setting up a Discourse server with Patreon integration. I have received the following error message when Patrons sign up for Discourse:

Patreon group membership callback failed for new user 7 with error: undefined method `add' for nil:NilClass.
/var/www/discourse/plugins/discourse-patreon/plugin.rb:166:in `block (3 levels) in activate!'
/var/www/discourse/plugins/discourse-patreon/plugin.rb:164:in `each'
/var/www/discourse/plugins/discourse-patreon/plugin.rb:164:in `block (2 levels) in activate!'
/var/www/discourse/lib/plugin/instance.rb:215:in `public_send'
/var/www/discourse/lib/plugin/instance.rb:215:in `block (2 levels) in add_model_callback'

The user registers using Patreon authentication. The user is created, patreon shows up under Associated Accounts but their Patreon data (Amount, Rewards) is not added to their profile, and they are not added to the group. If I click on Update Patreon Data & Sync Groups, then the data shows up and they are added to the group successfully.

They are not new Patrons. They have been Patrons for a long time and are only now joining Discourse.

I’m now running the current version - 2.4.0.beta4. It’s on my own server, but a standard install.

Before updating to this version, I did deactivate the plugin, and deleted and recreated the Client Key. (A desperate attempt to resolve a problem which was actually fixed by the new version…) I wonder whether I have “broken” the configuration around the patrons group somehow, although it does seem odd that the Sync works, but registering a new user doesn’t.

I just did a test using a test user:

  1. Create test user in Patreon, with pledge to my campaign. (Webhook is triggered, but I don’t think this is relevant as the problem occurs with “old” Patrons.)
  2. Click on Update Patreon Data & Sync Groups, wait for async message that data has been updated.
  3. Register test user in Discourse.
  4. Check Patreon data for test user. No Patreon section - Amount, Rewards. User not included in patrons group.
  5. Click on Update Patreon Data & Sync Groups, wait for async message that data has been updated.
  6. Check Patreon data for test user. Patreon section now present, with Amount, Rewards. User is included in patrons group.

Thanks in advance for any help!

Any thoughts on this @vinothkannans?

I poked around the code a little and I saw that the group assignment functionality is handled in two spots:

  1. add_model_callback in plugin.rb which handles the registration of a single new user.
  2. sync_groups in patron.rb which handles the batch synchronization of group membership for all members.

My experience is the sync_groups works and add_model_callback doesn’t.

I noticed that sync_groups includes the following line:

next if group.nil?

Do we need the same line in add_model_callback? (Before line 166.)

That would stop the exception being thrown, but I don’t know whether it would make everything correct. I don’t know the code or the data model, so it’s pretty much a guess.

3 Likes

Yes, you’re correct. Thanks for the report. It’s fixed in the below commit

https://github.com/discourse/discourse-patreon/commit/15255a6d69492d14a2dd785c089809d391331781

2 Likes

Thank you, @vinothkannans!

3 Likes