Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Better handling of previously enabled Devise model deserialization #1805

Merged
merged 1 commit into from

3 participants

@rosenfeld

See issue #1800

@travisbot

This pull request passes (merged 6c943c79 into 3752981).

@josevalim josevalim commented on the diff
lib/devise/rails/warden_compat.rb
((6 lines not shown))
begin
- ActiveSupport::Inflector.constantize(klass).serialize_from_session(*args)
+ klass = ActiveSupport::Inflector.constantize(klass_name)
+ if klass.respond_to? :serialize_from_session
+ klass.serialize_from_session(*args)
+ else
+ Rails.logger.warn "[Devise] Stored serialized class #{klass_name} seems not to be Devise enabled anymore. Did you do that on purpose?"
@josevalim Owner

We should return nil here.

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

Good catch, I've rebased it against master and committed --amend with the nil return value fix

@josevalim josevalim merged commit 67f2074 into plataformatec:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 4 deletions.
  1. +10 −4 lib/devise/rails/warden_compat.rb
View
14 lib/devise/rails/warden_compat.rb
@@ -21,17 +21,23 @@ def serialize(record)
end
def deserialize(keys)
- klass, *args = keys
+ klass_name, *args = keys
begin
- ActiveSupport::Inflector.constantize(klass).serialize_from_session(*args)
+ klass = ActiveSupport::Inflector.constantize(klass_name)
+ if klass.respond_to? :serialize_from_session
+ klass.serialize_from_session(*args)
+ else
+ Rails.logger.warn "[Devise] Stored serialized class #{klass_name} seems not to be Devise enabled anymore. Did you do that on purpose?"
@josevalim Owner

We should return nil here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ nil
+ end
rescue NameError => e
if e.message =~ /uninitialized constant/
- Rails.logger.debug "[Devise] Trying to deserialize invalid class #{klass}"
+ Rails.logger.debug "[Devise] Trying to deserialize invalid class #{klass_name}"
nil
else
raise
end
end
end
-end
+end
Something went wrong with that request. Please try again.