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

Better double checked locking in load_schema #37288

Merged
merged 1 commit into from Sep 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions activerecord/lib/active_record/model_schema.rb
Expand Up @@ -478,6 +478,9 @@ def load_schema
load_schema!

@schema_loaded = true
rescue
reload_schema_from_cache # If the schema loading failed half way through, we must reset the state.
raise
end
end

Expand Down
16 changes: 16 additions & 0 deletions activerecord/test/cases/base_test.rb
Expand Up @@ -77,6 +77,22 @@ def test_generated_relation_methods_module_name
assert_equal "Post::GeneratedRelationMethods", mod.inspect
end

def test_incomplete_schema_loading
topic = Topic.first
payload = { foo: 42 }
topic.update!(content: payload)

Topic.reset_column_information

Topic.connection.stub(:lookup_cast_type_from_column, ->(_) { raise "Some Error" }) do
assert_raises RuntimeError do
Topic.columns_hash
end
end

assert_equal payload, Topic.first.content
end

def test_column_names_are_escaped
conn = ActiveRecord::Base.connection
classname = conn.class.name[/[^:]*$/]
Expand Down