Skip to content

Assigning undefined jsonb values overwrites non-jsonb values in v1.3.3  #148

@yurikoval

Description

@yurikoval

v1.3.3 seems to have broken attribute assignment for values that are not defined in jsonb.
If you happen to have a key that has the same name as an attribute (non-jsonb) in ActiveRecord, it ends up overwriting it.
Expected behaviour would be to store the data, but not overwrite non-jsonb attributes.

create_table "products" do |t|
  t.jsonb "data"
end

class Product < ActiveRecord::Base
  jsonb_accessor :data, title: :string
end
product = Product.new
product.created_at # nil
product.data = {title: "hello world", created_at: 1.year.ago}
product.title # "hello world"
product.created_at # "2021-08-19T15:40:42+08:00" (this should be nil)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions