Closed FraDim closed 5 years ago
When creating a resource with valid fields in Forest Admin Then the resource should be created and displayed
When creating a resource with valid fields in Forest Admin Then I get a popup with the message
wrong number of arguments (given 2, expected 0..1)
And no resource has been created
Where InventoryLevel is the resource that I tried to create (snipped for clarity):
InventoryLevel
Started POST "/forest/InventoryLevel" for 127.0.0.1 at 2019-05-13 12:57:50 +0100 Processing by ForestLiana::UserSpace::InventoryLevelController#create as JSON Parameters: { "data" => { "attributes" => { "quantity_available" => 2 }, "type" => "InventoryLevels" }, "collection" => "InventoryLevel" } Completed 400 Bad Request in 306ms (Views: 0.6ms | ActiveRecord: 3.2ms | Allocations: 140946)
The method ResourceCreator#has_strong_parameter checks for the arity of ActiveRecord::Persistence#update_attributes! in order to decide whether to create the record with the option without_protection or not.
ActiveRecord::Persistence#update_attributes!
without_protection
The problem arises because the update_attributes! method is deprecated in Rails 6 and is now an alias of the update! method (in the past it has been the opposite) and the arity check returns an unexpected value:
update_attributes!
update!
ActiveRecord::Base.instance_method(:update!).arity # => 1 ActiveRecord::Base.instance_method(:update_attributes!).arity # => -1
This causes the option without_protection: true to be passed to the create method of ActiveRecord, which is not accepted.
without_protection: true
create
ActiveRecord
Hi @FraDim It should be fixed with the liana v4.1.0.
Feel free to reopen this ticket if the issue persists.
Expected behavior
When creating a resource with valid fields in Forest Admin Then the resource should be created and displayed
Actual behavior
When creating a resource with valid fields in Forest Admin Then I get a popup with the message
And no resource has been created
Failure Logs
Where
InventoryLevel
is the resource that I tried to create (snipped for clarity):Context
Debugging
The method ResourceCreator#has_strong_parameter checks for the arity of
ActiveRecord::Persistence#update_attributes!
in order to decide whether to create the record with the optionwithout_protection
or not.The problem arises because the
update_attributes!
method is deprecated in Rails 6 and is now an alias of theupdate!
method (in the past it has been the opposite) and the arity check returns an unexpected value:This causes the option
without_protection: true
to be passed to thecreate
method ofActiveRecord
, which is not accepted.