AaronLasseigne / active_interaction

:briefcase: Manage application specific business logic.
MIT License
2.07k stars 137 forks source link

Incorrect filtering of array of hashes in v5? #537

Closed asabourin closed 2 years ago

asabourin commented 2 years ago

Hi @AaronLasseigne and team, we have stumbled upon a change in behaviour while trying to upgrade to version 5.0.0, which can be seen with the below action:

class TestArrayOfHashes < ActiveInteraction::Base
  hash :hash do
    string :required_attribute
    string :option_with_default, :default => "foo"
  end

  array :array_of_hashes do
    hash do
      string :required_attribute
      string :option_with_default, :default => "foo"
    end
  end

  def execute
    inputs
  end
end

Running with dummy data such as

TestArrayOfHashes.run!(
  :hash => {:required_attribute => "foo", :something_else => "bar"},
  :array_of_hashes => [{:required_attribute => "foo", :something_else => "bar"}]
)

we get the expected output in version 4.1, where something_else is filtered out and option_with_default is added with its default value in both the hash and array of hashes:

{
  :array_of_hashes=>[{"required_attribute"=>"foo", "option_with_default"=>"foo"}],
  :hash=>{"required_attribute"=>"foo", "option_with_default"=>"foo"}
}

however with 5.0 we get:

{
  :array_of_hashes=>[{:required_attribute=>"foo", :something_else=>"bar"}],
  :hash=>{"required_attribute"=>"foo", "option_with_default"=>"foo"}
}

It looks like the extra attribute something_else is not filtered out and the optional option_with_default isn't set anymore for the array of hashes.

Is this a bug or is there perhaps a different way of declaring the array of hashes filter in version 5.0.0?

Thanks for your help!

AaronLasseigne commented 2 years ago

Fixed in the now released 5.1.0.