Devise::SecretKeyFinder#find deprioritizes use of the deprecated find method in rails#5604
Conversation
…nd method in `rails`.
|
Can you explain how did you expect to avoid this deprecation by moving it to the end? Does that means that in your application you have |
|
OK. Specifically, if In the current behavior, despite not using # Before
def find
if @application.respond_to?(:credentials) && key_exists?(@application.credentials)
@application.credentials.secret_key_base
# ↓↓ deprecation warning in if statement
elsif @application.respond_to?(:secrets) && key_exists?(@application.secrets)
@application.secrets.secret_key_base
# ↓↓ Actually get the value here
elsif @application.config.respond_to?(:secret_key_base) && key_exists?(@application.config)
@application.config.secret_key_base
elsif @application.respond_to?(:secret_key_base) && key_exists?(@application)
@application.secret_key_base
end
endHowever, by moving the execution order of the if statement ( # After
def find
if @application.respond_to?(:credentials) && key_exists?(@application.credentials)
@application.credentials.secret_key_base
# ↓↓ Get the value here and exit the if statement
elsif @application.config.respond_to?(:secret_key_base) && key_exists?(@application.config)
@application.config.secret_key_base
elsif @application.respond_to?(:secret_key_base) && key_exists?(@application)
@application.secret_key_base
# ↓↓ Never reach this if statement where the deprecation warning is raised
elsif @application.respond_to?(:secrets) && key_exists?(@application.secrets)
@application.secrets.secret_key_base
end
endSince the above two acquisition methods are not deprecated, I thought that extra deprecation warnings should not be output. |
|
My first thought on this was to shift to a Rails version check with three checks in order:
This ensures that the priority order is unaffected and respects the deprecations for the version. def find
credential_store = Rails.gem_version >= Gem::Version.new("7.2.x") ? :credential : :secrets
if @application.respond_to?(credential_store) && key_exists?(@application.public_send(credential_store))
@application.public_send(credential_store).secret_key_base
elsif @application.config.respond_to?(:secret_key_base) && key_exists?(@application.config)
@application.config.secret_key_base
elsif @application.respond_to?(:secret_key_base) && key_exists?(@application)
@application.secret_key_base
end
end |
|
@rgarver |
|
A couple of things:
def find
if @application.respond_to?(:secret_key_base) && key_exists?(@application)
@application.secret_key_base # Handles fallback logic since Rails 5.2
elsif @application.respond_to?(:secrets) && key_exists?(@application.secrets)
# Suppported since Rails 4.1
@application.secrets.secret_key_base
elsif @application.config.respond_to?(:secret_key_base) && key_exists?(@application.config)
# Support really unusual configurations for backward compatibility
@application.config.secret_key_base
end
end |
|
@soartec-lab thanks for submitting this PR 👍 If you weren't aware, EDIT: Found a better PR. |
|
closed by #5645 |
The
rails/railsrepository has deprecatedrails.application.secretsdue to this PR.Devise::SecretKeyFinder#findsequentially examines the variables stored by searchingsecret_key_base, but deprecatedRails.application.secretsis searched first, so in many cases A warning will occur. This is noise in many cases.To fix this, I changed the search order so that the deprecated
Rails.application.secretsdoesn't take precedence.