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

How do we want to handle inspecting an ActiveRecord instance in production? #1238

Open
stevepolitodesign opened this issue Nov 6, 2024 · 6 comments
Labels
Discussion Needs feedback

Comments

@stevepolitodesign
Copy link
Contributor

rails/rails#49765 makes it so

By default, calling inspect on a record will yield a formatted string including just the id.

However, this has lead to confusion, as noted in rails/rails#52728

@stevepolitodesign
Copy link
Contributor Author

If we find this is not desireable, we can set config.active_record.attributes_for_inspect = :all in production.

@stevepolitodesign stevepolitodesign added the Discussion Needs feedback label Nov 6, 2024
@stevepolitodesign
Copy link
Contributor Author

Noting that this has the benefit of hidding potentionally sensitive or identifiable information, which can be seen as a security improvement.

However, one could always call #attributes to get past this.

@emilford
Copy link
Contributor

emilford commented Nov 6, 2024

If I remember correctly, performance was another driver behind the change. I'm in favor of keeping the default. It's jarring at first when you're used to the prior behavior, but I've come to accept it with time. It's easy enough to use attributes and it's one less deviation from Rails' defaults.

@louis-antonopoulos
Copy link
Contributor

I support staying with the default in Production. As a helper to those who might be surprised by the new behavior, maybe we could add a commented-out section to production.rb to make it easier for people to override it?

# Enabling this does [...]
# config.active_record.attributes_for_inspect = :all

@dvodvo
Copy link

dvodvo commented Nov 18, 2024

If we find this is not desireable, we can set config.active_record.attributes_for_inspect = :all in production.

Minor issue: gem defines gem 'rails', '~> 7.1', '>= 7.1.3.4'
even with that line added to production environment
console still returns

RAILS_ENV=production bundle exec rails c
Loading production environment (Rails 7.2.1.2)
Transaction.last
  Transaction Load (0.7ms)  SELECT "transactions".* FROM "transactions" ORDER BY "transactions"."id" DESC LIMIT $1  [["LIMIT", 1]]
=> #<Transaction:0x00007f3d44c20938 id: 1989849>
fidelity(prod)> Transaction.last.inspect
  Transaction Load (0.6ms)  SELECT "transactions".* FROM "transactions" ORDER BY "transactions"."id" DESC LIMIT $1  [["LIMIT", 1]]
=> "#<Transaction id: 1989849>"
Transaction.last.full_inspect
  Transaction Load (0.4ms)  SELECT "transactions".* FROM "transactions" ORDER BY "transactions"."id" DESC LIMIT $1  [["LIMIT", 1]]
=> "#<Transaction id: 1989849, user_id: 17473, [...], created_at: \"2024-11-17 22:38:39.381984000 +0100\", updated_at: \"2024-11-17 22:38:39.381984000 +0100\">"

but enough that's nitpicking and may be a version issue quickly resolved.

It took me a while to scroll through issues to find the full_inspect command. (consider I was frantically searching to see data after an major upgrade)...

I see the point of full_inspect as a counter to inspect, but does that not just make inspect devoid of its own meaning?
Am I missing something?

my two schekles worth: I see the point and support dealing with load times by default in production.
However, inspect should be inspect with no need for full_inspect (unless that does something of greater value).
(the attributes_for_inspect should not even be something to be defined).
Only a minimum of experience in writing controller tests is required to think of inspect and give it a whirl... avoid frantic searching, and post long-winded comments [guilty] => so there would be near-zero need to have any prompt suggestion.

@greutter
Copy link

greutter commented Nov 21, 2024

From the perspective of new comers not having config.active_record.attributes_for_inspect = :all in production makes a less friendly and welcoming experience. Making this more obscure.

Turning off is a task easily accomplished by seasoned developers. For newbies the reverse is true.

If we want a bigger community it's better to show all beautiful aspects of rails (including it's console)

Don't let performance rule over developer happiness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion Needs feedback
Projects
None yet
Development

No branches or pull requests

5 participants