Skip to content


Subversion checkout URL

You can clone with
Download ZIP


stack level too deep in registration create #1

mehayden opened this Issue · 7 comments

2 participants


Was using this gem with devise (1.3.4), sequel (3.23.0), orm_adapter (0.0.5), orm_adapter-sequel (0.0.2)
After changing to devise (1.5.2) and sequel (3.30.0) (others same)
Got exception:

SystemStackError in Devise::RegistrationsController#create

stack level too deep

devise (1.5.2) lib/devise/models/database_authenticatable.rb:108:in downcase_keys'
devise_sequel (0.0.3) lib/devise/orm/sequel/compatibility.rb:48:in
devise_sequel (0.0.3) lib/devise/orm/sequel/compatibility.rb:57:in orig_before_validation'
devise_sequel (0.0.3) lib/devise/orm/sequel/compatibility.rb:60:in
devise_sequel (0.0.3) lib/devise/orm/sequel/compatibility.rb:60:in before_validation'
sequel (3.30.0) lib/sequel/model/base.rb:1537:in
sequel (3.30.0) lib/sequel/model/base.rb:796:in around_validation'
sequel (3.30.0) lib/sequel/model/base.rb:1535:in
sequel (3.30.0) lib/sequel/model/base.rb:1153:in save'
sequel (3.30.0) lib/sequel/model/base.rb:1569:in
sequel (3.30.0) lib/sequel/model/base.rb:1153:in save'
devise (1.5.2) app/controllers/devise/registrations_controller.rb:16:in


I have not updated this in awhile and fell behind on version updates.

I will get the newer gems and see what is the problem here.

Thanks for reporting the issue!


I think the problem is that wrap_hook is non-re-entrant. The second time it is called with the same action it will set orig_before_validation to the redefined before_validation not the real original one. So the attempted call to the real one at the end of the class_eval'd function actually calls itself.

Note that in version 1.5.2 of Devise there are 2 calls to before_validation in models/authenticatable.rb

61: before_validation :downcase_keys
62: before_validation :strip_whitespace

whereas in version 1.3.4 there are no calls to before_validation.

@mehayden mehayden closed this
@mehayden mehayden reopened this

Hey thanks for looking into this. redefining those hooks was never a good idea! I've been setting up tests to work with the new Devise but haven't had much time to rewriting some of the code itself.

Have you looked at arthurdandrea's fork? he seemed to have done quite a bit of change that could address this. I am looking into his changes and hope to combine our efforts.


I tried arthurdandrea's fork and I got a "wrong number of arguments 2 for 1" error during the application loading. I wasn't sure where :before_create was being defined. Then I poked around and found ActiveModel::Callbacks and tried adding the following to my User class:

extend ActiveModel::Callbacks
define_model_callbacks :create, :update, :validation

Now the devise callbacks seem to work.


Perhaps a better way to do this is to add the following lines to the end of Sequel::Plugins::Devise.apply

    # enable callbacks used by Devise
    model.extend ::ActiveModel::Callbacks
    model.define_model_callbacks :create, :update, :validation

On further testing, it looks like the confirmable hooks are not being called during the lifecycle:

before_create :generate_confirmation_token, :if => :confirmation_required?
after_create :send_confirmation_instructions, :if => :confirmation_required?

Although I think database_authenticatable hooks are being called:

before_validation :downcase_keys
before_validation :strip_whitespace

since I can log in using uppercase letters in the email. This may indicate that the :if option used in confirmable could be the culprit.


I've implemented a fix for the issues I was seeing with Devise 1.5.2 in a fork I made from arthurdandrea's fork. See:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.