-
Notifications
You must be signed in to change notification settings - Fork 21.9k
ActiveRecord::Base.attributes_for_inspect
should default to :all
#52753
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
Conversation
@@ -291,6 +291,7 @@ def load_defaults(target_version) | |||
active_record.marshalling_format_version = 7.1 | |||
active_record.run_after_transaction_callbacks_in_order_defined = true | |||
active_record.generate_secure_token_on = :initialize | |||
active_record.attributes_for_inspect = :all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I think we want this in the 7.2
(line 324) clause of this case statement, as this method will not exist in 7.1
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it! I also see this caused a linter issue by adding this. Working out how to fix that.
Please, keep only 1 commit in the PR. |
Co-authored-by: Petrik de Heus <petrik@deheus.net>
bef007a
to
43dfd8b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this!
To maintain backwards compatibility with < 7.2, we'll need the default to be :all
, not just when load_defaults 7.2
. I believe that change needs to be in activerecord/lib/active_record/core.rb
.
@@ -336,6 +336,7 @@ def load_defaults(target_version) | |||
if respond_to?(:active_record) | |||
active_record.postgresql_adapter_decode_dates = true | |||
active_record.validate_migration_timestamps = true | |||
active_record.attributes_for_inspect = :all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
active_record.attributes_for_inspect = :all | |
active_record.attributes_for_inspect = [:id] |
This one should be the new default that apps can opt into when they load_defaults 7.2
after upgrading.
(The line may have to be more complicated than this... maybe
[:id] unless Rails.env.local?
or something similar?)
|
||
| Starting with version | The default value is | | ||
| --------------------- | -------------------- | | ||
| 7.2 | :all | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 7.2 | :all | | |
| (original) | :all | | |
| 7.2 | [:id] | |
(or whatever the :id
value ends up being)
@@ -66,6 +66,7 @@ Below are the default values associated with each target version. In cases of co | |||
#### Default Values for Target Version 7.2 | |||
|
|||
- [`config.active_job.enqueue_after_transaction_commit`](#config-active-job-enqueue-after-transaction-commit): `:default` | |||
- [`config.active_record.attributes_for_inspect`](#config-active-record-attributes-for-inspect): `:all` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- [`config.active_record.attributes_for_inspect`](#config-active-record-attributes-for-inspect): `:all` | |
- [`config.active_record.attributes_for_inspect`](#config-active-record-attributes-for-inspect): `[:id]` |
Yes @skipkayhil is right, the default in But, we want existing apps to not get that by default, so we need to also change the default for the attribute in AR base to be Additionally, I believe that this initializer will now serve no purpose, since For an example of this being done right you can take a look at this PR which introduces Sorry for missing this detail on friday @levicole ! |
Implementing this properly is very hard. When I still think the best solution here is the custom inspector for console. |
Even the custom inspector for the console will not help much because the pretty print format also uses the I think I'll decide that we should not mix the two concerns on this implementation. The only thing I care about right now is to not inadvertently Allowing people to configure how to see things in console and debug is a nice to have, but I'd prefer to not change it if it makes things harder to debug. So changing |
@rafaelfranca do you want me to just close this then? |
Let's see what Andrew has to say. I'll update this PR and merge so we don't lose your work. |
@rafaelfranca Instead of trying to change the framework defaults to get precisely the settings we want, why don't we just set
That even still allows to the user to overwrite it further if they actually do want different attributes in production. Then we don't have to deal with adding the new framework default at this point, which tbh I am still not convinced is needed since this is a performance fix and shouldn't be noticed in production (outside debugging). What do you think? |
@levicole I discussed with Rafael offline and decided we should set |
@andrewn617 Awesome! Thanks for YOUR help! I'll close this! |
Motivation / Background
After updating to Rails 7.2, we noticed that attributes were missing when inspecting AR objects in a production-like console. We found #49765. After discussing this with @rafaelfranca and the author of the PR, @andrewn617, we came to the conclusion that this should default to
:all
.Detail
This PR changes the default of
attributes_for_inspect
to:all
. There's a commit on this branch that also updated the Rails 7.2 new defaults initializer, but I removed that as it's not on main and I'm unsure how to handle that.Additional information
This PR is going off of a discussion with @rafaelfranca. It's possible there is more to change here to make this work properly, and I apologize if thats the case. Happy to make more updates. I'm curious if, since we want new Rails applications to have this default set to true, if the
production.rb
environment file should be updated to include the configuration change.Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]