sorcery: NoMethodError, when creating a new User

Configuration

  • Sorcery Version: 0.15.0
  • Ruby Version: 3.0.0
  • Framework: Rails 6.1.1
  • Platform: macOS 11.1

Expected Behavior

A new user is meant to be created.

Actual Behavior

Since updating to sorcery 0.15.0 I am getting the following error when I try to run User.create in the rails console.

NoMethodError (undefined method `after_save' for {:if=>#<Proc:0x00007fcb22b96cd0 /Users/alan/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sorcery-0.15.0/lib/sorcery/model.rb:69>}:Hash)

Steps to Reproduce

See below for when I run the User.create

irb(main):001:0> user = User.create(email: 'alan@example.com')
  TRANSACTION (0.1ms)  BEGIN
  User Exists? (1.1ms)  SELECT 1 AS one FROM "users" WHERE "users"."slug" = $1 LIMIT $2  [["slug", "8c8b4b303a"], ["LIMIT", 1]]
  User Create (0.9ms)  INSERT INTO "users" ("slug", "email", "created_at", "updated_at") VALUES ($1, $2, $3, $4) 
  RETURNING "id"  [["slug", "8c8b4b303a"], ["email", "alan@example.com"], 
                                  ["created_at", "2021-01-18 12:05:58.962942"], 
                                  ["updated_at", "2021-01-18 12:05:58.962942"]]
  TRANSACTION (0.2ms)  ROLLBACK
Traceback (most recent call last):
        1: from (irb):1:in `<main>'
NoMethodError (undefined method `after_save' for {:if=>#<Proc:0x00007fcb22b96cd0
/Users/alan/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sorcery-0.15.0/lib/sorcery/model.rb:69>}:Hash)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (5 by maintainers)

Most upvoted comments

I just discovered the master branch is already fixed…

Working on cutting a new release in the near future…

@ccokme Thank you! I’ll take a look at this when I have the time and see if I can’t figure out what the deal is.

@ccokme Would you be willing to create a new rails app and recreate the issue with as little code as possible? It would be immensely helpful for me tracking down where this is coming from.

Sure thing, i just created a new rails app with the same version of mongoid/rails/ruby/sorcery, https://github.com/ccokme/sorcery_test_app, you just have to run mongodb on your dev, and then enter the rails console:

3.0.1 :005 > User.new.save
/usr/local/rvm/gems/ruby-3.0.1/gems/activesupport-6.1.3.2/lib/active_support/callbacks.rb:427:in `block in make_lambda': undefined method `after_save' for {:if=>#<Proc:0x00007fd42837cb30 /usr/local/rvm/gems/ruby-3.0.1/gems/sorcery-0.16.1/lib/sorcery/model.rb:69>}:Hash (NoMethodError)

@r3id Weird indeed. I’ll have a look at the tut if I have a moment to spare.