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

attributes_for_inspect config doesn't seem to work #53665

Closed
siaw23 opened this issue Nov 18, 2024 · 4 comments
Closed

attributes_for_inspect config doesn't seem to work #53665

siaw23 opened this issue Nov 18, 2024 · 4 comments

Comments

@siaw23
Copy link
Member

siaw23 commented Nov 18, 2024

Steps to reproduce

# frozen_string_literal: true

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  gem "rails"
  # If you want to test against edge Rails replace the previous line with this:
  # gem "rails", github: "rails/rails", branch: "main"

  gem "sqlite3"
end

require "active_record/railtie"
require "minitest/autorun"

# This connection will do for database-independent bug reports.
ENV["DATABASE_URL"] = "sqlite3::memory:"

class TestApp < Rails::Application
  config.load_defaults Rails::VERSION::STRING.to_f
  config.eager_load = false
  config.logger = Logger.new($stdout)
  config.active_record.attributes_for_inspect = [ :id, :created_at ]
end
Rails.application.initialize!

ActiveRecord::Schema.define do
  create_table :posts, force: true do |t|
  end
end

class Post < ActiveRecord::Base
end

class BugTest < ActiveSupport::TestCase
  def test_association_stuff
    post = Post.create!

    assert_equal "#<Post id: 1, created_at: '2024-11-18 20:39:16.588940000 +0000'>", Post.first.inspect
  end
end

Expected behavior

I expect to see just the id and created_at attributes when I do Post.first.inspect

Actual behavior

In my console, I see ALL the attributes, config.active_record.attributes_for_inspect doesn't respect the attributes I pass to it. In the reproduction script above however, something different happens, it shows ONLY the id without the created_at.

System configuration

Rails version: "8.0.0"

Ruby version: "3.3.0"

cc: @p8 @andrewn617

@siaw23 siaw23 changed the title attributes_for_inspect config doesn't seem to work attributes_for_inspect config doesn't seem to work Nov 18, 2024
@skipkayhil
Copy link
Member

#53475

@siaw23
Copy link
Member Author

siaw23 commented Nov 19, 2024

@skipkayhil thanks for the response. That reference doesn't help in anyway I'm afraid.

Here's what I have in my development.rb

Rails.application.configure do
  config.active_record.attributes_for_inspect = [ :id ]

And here's some output in my dev console:

app(dev)> User.first.inspect
  User Load (0.1ms)  SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1 /*application='App'*/
=> "#<User id: 1, name: \"Emmanuel\", created_at: \"2024-11-19 09:11:34.635605000 +0000\", updated_at: \"2024-11-19 09:11:34.635605000 +0000\", email: [FILTERED]>"
app(dev)> User.attributes_for_inspect
=> :all
app(dev)>

I expect User.attributes_for_inspect to be :id, it's :all and that's leading me to thinking something's broken.

More over, if I explicitly set the attributes_for_inspect in the dev console it doesn't seem to work either. Like so:

app(dev)> User.attributes_for_inspect = [ :id, :name ]
=> [:id, :name]
app(dev)> User.attributes_for_inspect
=> [:id, :name]
app(dev)> User.first.inspect
  User Load (0.8ms)  SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1 /*application='App'*/
=> "#<User id: 1, name: \"Emmanuel\", created_at: \"2024-11-19 09:11:34.635605000 +0000\", updated_at: \"2024-11-19 09:11:34.635605000 +0000\", email: [FILTERED]>"

@p8
Copy link
Member

p8 commented Nov 19, 2024

@siaw23 In the console we always show all attributes.
See motivation in this issue: #52801

We should always use :all in the production console to not hinder debugging/

@byroot
Copy link
Member

byroot commented Dec 12, 2024

Closing since apparently that's desired behavior.

@byroot byroot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants