Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix EncryptedConfiguration not behaving like Hash #48556

Merged
merged 1 commit into from
Jun 22, 2023

Conversation

skipkayhil
Copy link
Member

Motivation / Background

Fixes #48554

Previously, EncryptedConfiguration was updated to use InheritableOptions so that keys could be called like methods. It was later updated again to ensure that it behaved both like a Hash and OrderedOptions. In this second change, the InheritableOptions instance was accidentally nested with another InheritableOptions instance.

This continued to mostly work as expected because InheritableOptions will fall back to the inner InheritableOptions when the outer one doesn't have a key. However, any methods that try to treat the outer InheritableOptions like it should know about all of its keys will fail (for example, #keys, #to_h, #to_json, etc.)

Detail

This commit fixes the issue by removing the extraneous outer InheritableOptions instance.

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

Previously, `EncryptedConfiguration` was [updated][1] to use
`InheritableOptions` so that keys could be called like methods. It was
later [updated again][2] to ensure that it behaved both like a `Hash` and
`OrderedOptions`. In this second change, the `InheritableOptions`
instance was accidentally nested with another `InheritableOptions`
instance.

This continued to mostly work as expected because `InheritableOptions`
will fall back to the inner `InheritableOptions` when the outer one
doesn't have a key. However, any methods that try to treat the outer
`InheritableOptions` like it should know about all of its keys will fail
(for example, `#keys`, `#to_h`, `#to_json`, etc.)

This commit fixes the issue by removing the extraneous outer
`InheritableOptions` instance.

[1]: a6a9fed
[2]: 80585da
@dorianmariecom
Copy link
Contributor

dorianmariecom commented Jun 22, 2023

Thanks a lot, it works

>> Rails.application.credentials.to_h
=> 
{:secret_key_base=> ...
...

@dorianmariecom
Copy link
Contributor

works great but maybe

>> Rails.application.credentials
=> #<ActiveSupport::EncryptedConfiguration:0x0000000000a668>

coudl be improved?

@skipkayhil
Copy link
Member Author

coudl be improved?

This is actually intentional, it was just changed last week in #48498

@dorianmariecom
Copy link
Contributor

Ok sure, I understand

@guilleiguaran
Copy link
Member

should we include this in the CHANGELOG for 7.1 if it's already present in the CHANGELOG for 7.0? (#48557)

@matthewd
Copy link
Member

Yes, the 7.1.0 changelog is relative to 7.0.0, not 7.0.latest.

@guilleiguaran guilleiguaran merged commit 06da26a into rails:main Jun 22, 2023
9 checks passed
@dorianmariecom
Copy link
Contributor

thx you all rock, and I'm using main so I will get it after the next bundle update :)

@skipkayhil skipkayhil deleted the hm-fix-encrypted-config-hash branch June 22, 2023 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Why is credentails.to_h/to_json empty when there are credentials?
4 participants