Swallow devise routing errors when re-setting database #2192

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
5 participants
@nthj

nthj commented Dec 29, 2012

I frequently run 'rake db:migrate:reset db:seed' when developing, to get back to my default mock-up state. Unfortunately, Devise assumes that the database table should exist at this point, and throws a SQL error. For example:

PG::Error: ERROR:  relation "users" does not exist

Since I'm trying to re-set the database, this is frustrating. I have to comment out the "devise_for" line in my routes.rb, run my migrations, then un-comment the devise_for line again.

This pull request simply swallows any exceptions from devise_for when running db:migrate.

@lucasmazza

This comment has been minimized.

Show comment Hide comment
@lucasmazza

lucasmazza Jan 5, 2013

Contributor

Hi @nthj,

I wasn't able to reproduce this scenario locally but I know how annoying things like this can be, but instead of swallowing any possible error isn't better to emit a warning and skip the whole routes setup?

Also, more input on this would be welcome. /cc @rodrigoflores @carlosantoniodasilva @josevalim

Contributor

lucasmazza commented Jan 5, 2013

Hi @nthj,

I wasn't able to reproduce this scenario locally but I know how annoying things like this can be, but instead of swallowing any possible error isn't better to emit a warning and skip the whole routes setup?

Also, more input on this would be welcome. /cc @rodrigoflores @carlosantoniodasilva @josevalim

@nthj

This comment has been minimized.

Show comment Hide comment
@nthj

nthj Jan 6, 2013

Hmm, so you would like a backtrace? Or a one-line warning? Or just skip route set up on db:migrate entirely, whether an error is thrown or not?

rake db:migrate:reset will throw the error for me.

nthj commented Jan 6, 2013

Hmm, so you would like a backtrace? Or a one-line warning? Or just skip route set up on db:migrate entirely, whether an error is thrown or not?

rake db:migrate:reset will throw the error for me.

@josevalim

This comment has been minimized.

Show comment Hide comment
@josevalim

josevalim Jan 30, 2013

Member

@nthj sorry for taking so long on this.

Can you provide an application that reproduces the issue?

Calling rake db:migrate:reset db:seed did not trigger it for it in any of our apps, which makes me suspect something more is going on. By default, Rails does not make queries when loading the model, so there is something in your model triggering a query. I don't know what it is, it may even be a has_many, but we need your help in finding it out.

Thank you.

Member

josevalim commented Jan 30, 2013

@nthj sorry for taking so long on this.

Can you provide an application that reproduces the issue?

Calling rake db:migrate:reset db:seed did not trigger it for it in any of our apps, which makes me suspect something more is going on. By default, Rails does not make queries when loading the model, so there is something in your model triggering a query. I don't know what it is, it may even be a has_many, but we need your help in finding it out.

Thank you.

@whoisjake

This comment has been minimized.

Show comment Hide comment
@whoisjake

whoisjake Feb 21, 2013

I'm having the same exact issue. Rake db loads environment, which loads routes, which upon calling devise_for :users , loads the model, which tries to load the fields. Chicken and egg

The lines in question goes to a scope like this:
scope :active, where(:deleted => 0, :disabled => 0)

https://gist.github.com/whoisjake/15604c08003cc37331be

I'm having the same exact issue. Rake db loads environment, which loads routes, which upon calling devise_for :users , loads the model, which tries to load the fields. Chicken and egg

The lines in question goes to a scope like this:
scope :active, where(:deleted => 0, :disabled => 0)

https://gist.github.com/whoisjake/15604c08003cc37331be

@lucasmazza

This comment has been minimized.

Show comment Hide comment
@lucasmazza

lucasmazza Feb 21, 2013

Contributor

@whoisjake can you provide an application that reproduces the issue?

Contributor

lucasmazza commented Feb 21, 2013

@whoisjake can you provide an application that reproduces the issue?

@whoisjake

This comment has been minimized.

Show comment Hide comment
@whoisjake

whoisjake Feb 21, 2013

Yup! Just created it: https://github.com/whoisjake/devise_model_failure

Easy to reproduce, in fact,

$ rails new my_app
$ rails generate devise:install
$ rails generate devise User

edit user.rb to include a scope like:

scope :have_not_logged_in, where(:sign_in_count => 0)
rake db:migrate

BOOM CRASH

Yup! Just created it: https://github.com/whoisjake/devise_model_failure

Easy to reproduce, in fact,

$ rails new my_app
$ rails generate devise:install
$ rails generate devise User

edit user.rb to include a scope like:

scope :have_not_logged_in, where(:sign_in_count => 0)
rake db:migrate

BOOM CRASH

@whoisjake

This comment has been minimized.

Show comment Hide comment
@whoisjake

whoisjake Feb 21, 2013

@lucasmazza

This comment has been minimized.

Show comment Hide comment
@lucasmazza

lucasmazza Feb 21, 2013

Contributor

@whoisjake thanks a lot. I managed to reproduce the error and the scope definition is causing the error. Maybe @josevalim or @rafaelfranca can shed a light on this.

Contributor

lucasmazza commented Feb 21, 2013

@whoisjake thanks a lot. I managed to reproduce the error and the scope definition is causing the error. Maybe @josevalim or @rafaelfranca can shed a light on this.

@whoisjake

This comment has been minimized.

Show comment Hide comment
@whoisjake

whoisjake Feb 21, 2013

So apparently the use of those types of scopes is "deprecated" in Rails edge...

https://github.com/rails/rails/blob/master/activerecord/lib/active_record/scoping/named.rb#L145

11 months ago...
rails/rails@0a12a5f

might have snuck in between 3.2.11 and 3.2.12 as that's a change I recently made...

So apparently the use of those types of scopes is "deprecated" in Rails edge...

https://github.com/rails/rails/blob/master/activerecord/lib/active_record/scoping/named.rb#L145

11 months ago...
rails/rails@0a12a5f

might have snuck in between 3.2.11 and 3.2.12 as that's a change I recently made...

@whoisjake

This comment has been minimized.

Show comment Hide comment
@whoisjake

whoisjake Feb 21, 2013

Ok, nope, 3.2.12 does not have the deprecation, but this might have been there all along anyway...

https://github.com/rails/rails/blob/v3.2.12/activerecord/lib/active_record/scoping/named.rb

Ok, nope, 3.2.12 does not have the deprecation, but this might have been there all along anyway...

https://github.com/rails/rails/blob/v3.2.12/activerecord/lib/active_record/scoping/named.rb

@josevalim

This comment has been minimized.

Show comment Hide comment
@josevalim

josevalim Feb 21, 2013

Member

Yeah, I was thinking about just suggesting to use lambda scopes. Since it
will fix the problem and your app will automatically work with Rails 4.

Member

josevalim commented Feb 21, 2013

Yeah, I was thinking about just suggesting to use lambda scopes. Since it
will fix the problem and your app will automatically work with Rails 4.

@whoisjake

This comment has been minimized.

Show comment Hide comment
@whoisjake

whoisjake Feb 21, 2013

Yeah, I mean, I can do that... but the issue is still there as with 3.2.12 it's a perfectly valid way to do scopes. I'll probably just change my scopes instead of waiting around.

Good luck!

Yeah, I mean, I can do that... but the issue is still there as with 3.2.12 it's a perfectly valid way to do scopes. I'll probably just change my scopes instead of waiting around.

Good luck!

@whoisjake

This comment has been minimized.

Show comment Hide comment
@whoisjake

whoisjake Feb 21, 2013

Ok, so I have confirmed that it's not a change in Devise. I went through each version back and the issue persisted. Upon changing from Rails 3.2.12 back to 3.2.11, it fails.

Ok, so I have confirmed that it's not a change in Devise. I went through each version back and the issue persisted. Upon changing from Rails 3.2.12 back to 3.2.11, it fails.

@whoisjake

This comment has been minimized.

Show comment Hide comment
@whoisjake

whoisjake Feb 21, 2013

rails/rails@v3.2.11...v3.2.12

I believe its this:
https://github.com/rails/rails/blob/1dccd44a5c74f20b0406ecc8d39373226f73af35/activerecord/lib/active_record/relation/predicate_builder.rb#L54

When the WHERE clause is an integer, it goes out to the schema cache...

So thanks. Probably should close this out...

rails/rails@v3.2.11...v3.2.12

I believe its this:
https://github.com/rails/rails/blob/1dccd44a5c74f20b0406ecc8d39373226f73af35/activerecord/lib/active_record/relation/predicate_builder.rb#L54

When the WHERE clause is an integer, it goes out to the schema cache...

So thanks. Probably should close this out...

@lucasmazza

This comment has been minimized.

Show comment Hide comment
@lucasmazza

lucasmazza Feb 21, 2013

Contributor

@whoisjake yes, and there's already some discussions about this on the Rails issue tracker. Thanks a lot for your help on digging this.

@nthj are you on the same scenario with Devise + Rails 3.2.12? If so, I think we can close this one.

Contributor

lucasmazza commented Feb 21, 2013

@whoisjake yes, and there's already some discussions about this on the Rails issue tracker. Thanks a lot for your help on digging this.

@nthj are you on the same scenario with Devise + Rails 3.2.12? If so, I think we can close this one.

@rafaelfranca

This comment has been minimized.

Show comment Hide comment
@rafaelfranca

rafaelfranca Feb 21, 2013

Collaborator

Related to rails/rails#9290

Collaborator

rafaelfranca commented Feb 21, 2013

Related to rails/rails#9290

@whoisjake

This comment has been minimized.

Show comment Hide comment
@whoisjake

whoisjake Feb 21, 2013

Well looks like others came to the same conclusion! Thanks y'all

Well looks like others came to the same conclusion! Thanks y'all

@josevalim josevalim closed this Feb 25, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment