Skip to content
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

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

Closed
yurikoval opened this issue Jul 21, 2022 · 1 comment · Fixed by #149
Closed

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

yurikoval opened this issue Jul 21, 2022 · 1 comment · Fixed by #149

Comments

@yurikoval
Copy link

yurikoval commented Jul 21, 2022

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)
@yurikoval yurikoval changed the title Assigning non-existing jsonb values overwrites AR values in v1.3.3 Assigning undefined jsonb values overwrites non-jsonb values in v1.3.3 Jul 21, 2022
@haffla
Copy link
Contributor

haffla commented Jul 23, 2022

Hello @yurikoval,

thanks for reporting this. I believe this bug had existed in v1.3.3 and before, too.

I've released v1.3.5 that fixes the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants