jsonb_accessor icon indicating copy to clipboard operation
jsonb_accessor copied to clipboard

Default Values: PG::InternalError: ERROR: Unexpected end of string

Open c2ofh opened this issue 1 year ago • 1 comments

Ruby: 3.1.4
Rails: 7.0.8.7
jsonb_accessor: 1.4

When Defining a jsonb_accessor with default values, the model can't be saved, cause this generates an error.

update(params[:settings].permit(:hermes, :widgets, :branding))
from /usr/share/rvm/gems/ruby-3.1.4/gems/activerecord-7.0.8.7/lib/active_record/connection_adapters/postgresql_adapter.rb:768:in `exec_params'
Caused by PG::InternalError: ERROR:  Unexpected end of string"

Tried 2 ways of defining the accessor:

jsonb_accessor :settings,
                hermes: [:boolean, { default: false }],
                widgets: [:integer, { default: 1 }],
                branding: [:boolean, { default: true }]
jsonb_accessor :settings,
                hermes: [:boolean, default: false],
                widgets: [:integer, default: 1],
                branding: [:boolean, default: true]

When I remove the default values, the update command works.

c2ofh avatar Feb 19 '25 20:02 c2ofh

@c2ofh can you please add a reproduction script? You can refer to example bugs in activerecord on how that looks like, you can hardcode in some connection parameters for PostgreSQL.

ashkulz avatar May 15 '25 04:05 ashkulz