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
Fix upsert
warning for MySQL
#51274
Merged
Merged
Fix upsert
warning for MySQL
#51274
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ class InsertAllTest < ActiveRecord::TestCase | |
|
||
def setup | ||
Arel::Table.engine = nil # should not rely on the global Arel::Table.engine | ||
@original_db_warnings_action = :ignore | ||
end | ||
|
||
def teardown | ||
|
@@ -336,6 +337,22 @@ def test_upsert_logs_message_including_model_name | |
end | ||
end | ||
|
||
def test_upsert_and_db_warnings | ||
skip unless supports_insert_on_duplicate_update? | ||
|
||
begin | ||
with_db_warnings_action(:raise) do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not worth doing here, more for a followup, but I wonder if it would make sense to run CI/tests with DB warnings treated as errors by default. I think it might have caught this issue way sooner. Also we probably should backport that fix. |
||
assert_nothing_raised do | ||
Book.upsert({ id: 1001, name: "Remote", author_id: 1 }) | ||
end | ||
end | ||
ensure | ||
# We need to explicitly remove the record, because `with_db_warnings_action` | ||
# prevents the wrapping transaction to be rolled back. | ||
Book.delete(1001) | ||
end | ||
end | ||
|
||
def test_upsert_all_logs_message_including_model_name | ||
skip unless supports_insert_on_duplicate_update? | ||
|
||
|
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.
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.
Currently, we have a couple of places that provide a
raw_update_sql
pointing to theVALUES(...)
, which, with this change, created a mixed query:The query didn't work as expected, and the expected behavior broke. We may need some way to keep using the previous behavior for a while. (I'm working on a PR unless someone beat me)
cc: @matthewd
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.
Yes. If the
raw_update_sql
is provided, we should not try to alias, because we don't even know the alias.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.
Created this PR to address this issue.