Filter virtual columns from the attribute names#43263
Merged
rafaelfranca merged 3 commits intorails:mainfrom Sep 20, 2021
Merged
Filter virtual columns from the attribute names#43263rafaelfranca merged 3 commits intorails:mainfrom
rafaelfranca merged 3 commits intorails:mainfrom
Conversation
Member
|
You could test this with diff --git a/activerecord/test/cases/adapters/postgresql/virtual_column_test.rb b/activerecord/test/cases/adapters/postgresql/virtual_column_test.rb
index fa6dcc51a6..7634baaeb4 100644
--- a/activerecord/test/cases/adapters/postgresql/virtual_column_test.rb
+++ b/activerecord/test/cases/adapters/postgresql/virtual_column_test.rb
@@ -34,6 +34,16 @@ def test_virtual_column
assert_equal "RAILS", VirtualColumn.take.upper_name
end
+ def test_virtual_column_with_full_inserts
+ partial_inserts_was = VirtualColumn.partial_inserts
+ VirtualColumn.partial_inserts = false
+ assert_nothing_raised do
+ VirtualColumn.create!(name: "Rails")
+ end
+ ensure
+ VirtualColumn.partial_inserts = partial_inserts_was
+ end
+
def test_stored_column
column = VirtualColumn.columns_hash["name_length"]
assert_predicate column, :virtual?
|
Contributor
Author
|
Done! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In a rails 7 app with
config.active_record.partial_inserts = false,If you have a model with virtual/generated columns AR tries to insert values into the columns when creating a new record.
This results in a PG::Error
Fixes #43262
Other Information
This opens up for another question:
Should
VirtualColumn.create(name: "Hello", upper_name: "hello")raise or just ignore the value forupper_nameThanks to @cristianbica for the help