You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In case of a JSON column, bulk_insert will incorrectly insert the default value. It inserts "{}" (ie. a string) instead of {} (ie. an object).
Here's a failing test:
beginrequire"bundler/inline"rescueLoadError=>e
$stderr.puts"Bundler version 1.10 or later is required. Please update your Bundler"raiseeendgemfile(true)dosource"https://rubygems.org"gem"rails"gem"sqlite3"gem"bulk_insert"endrequire"active_record"require"minitest/autorun"require"logger"# This connection will do for database-independent bug reports.ActiveRecord::Base.establish_connection(adapter: "sqlite3",database: ":memory:")ActiveRecord::Base.logger=Logger.new(STDOUT)ActiveRecord::Schema.definedocreate_table:profiles,force: truedo |t|
t.string:namet.json:json_data,default: {},null: falseendendclassProfile < ActiveRecord::BaseendclassBugTest < Minitest::Testdeftest_bulk_insert_json_defaultworker=Profile.bulk_insertworker.add(name: "Foo",json_data: {})worker.add(name: "Bar")worker.save!profile1=Profile.find_by!(name: "Foo")profile2=Profile.find_by!(name: "Bar")assert_equalprofile1.json_data,{}assert_equalprofile2.json_data,{}endend
In case a value does not exist, the column default is used. The column default in rails is expressed as a string (ie. in the example above: Profile.columns_hash["json_data"].default == {}). This is problematic for JSON columns, as both "{}" and {} are valid JSON (one a string, the other an object).
The text was updated successfully, but these errors were encountered:
In case of a JSON column,
bulk_insert
will incorrectly insert the default value. It inserts"{}"
(ie. a string) instead of{}
(ie. an object).Here's a failing test:
The reason is the following code:
bulk_insert/lib/bulk_insert/worker.rb
Lines 51 to 64 in ab5db08
In case a value does not exist, the column default is used. The column default in rails is expressed as a string (ie. in the example above:
Profile.columns_hash["json_data"].default == {}
). This is problematic for JSON columns, as both"{}"
and{}
are valid JSON (one a string, the other an object).The text was updated successfully, but these errors were encountered: