ActiveRecord::Store
with JSON column uses nil
as default value instead of {}
#50960
Labels
ActiveRecord::Store
with JSON column uses nil
as default value instead of {}
#50960
Steps to reproduce
Expected behavior
When using
ActiveRecord::Store
with a column of typejson
, the default value written to the database should be an emptyHash
(serialized as an empty JSON object{}
), especially if the attribute is marked as having a default value of{}
.Actual behavior
When using
ActiveRecord::Store
with a column of typejson
, the default value written to the database isnil
.This is problematic when using non-nullable JSON columns, which cannot accept defaults at the database schema level, as there is no way to avoid violating the
NULL
constraint.System configuration
Rails version: rails 7.1.3
Ruby version: ruby 3.3.0
The text was updated successfully, but these errors were encountered: