Skip to content

Conversation

@amclain
Copy link
Member

@amclain amclain commented Dec 4, 2025

This PR fixes an issue in Attribute.merge where it was assumed if a param from the original payload didn't exist, it should be initialized with an empty map (%{}). However, this didn't account for when an empty list ([]) should be initialized instead. This would be the case if the next path element is an integer.

This PR removes the early initialization of the missing parameter, and defers it to the next merge handler that should be called based on the next part of the path.

This bug would raise the following error:

  1) test merge nested lists (Speck.ValidationMetadata.Attribute.Test)
     test/validation_metadata/attribute_test.exs:15
     ** (FunctionClauseError) no function clause matching in List.insert_at/3

     The following arguments were given to List.insert_at/3:

         # 1
         %{}

         # 2
         -1

         # 3
         %{"id" => 1001}

     Attempted function clauses (showing 1 out of 1):

         def insert_at(list, index, value) when is_list(list) and is_integer(index)

     code: assert Attribute.merge(attributes, params) == %{
     stacktrace:
       (elixir 1.18.3) lib/list.ex:776: List.insert_at/3
       (speck 4.0.0) lib/speck/validation_metadata/attribute.ex:46: Speck.ValidationMetadata.Attribute.merge/4
       (speck 4.0.0) lib/speck/validation_metadata/attribute.ex:65: Speck.ValidationMetadata.Attribute.merge/4
       (speck 4.0.0) lib/speck/validation_metadata/attribute.ex:46: Speck.ValidationMetadata.Attribute.merge/4
       (speck 4.0.0) lib/speck/validation_metadata/attribute.ex:65: Speck.ValidationMetadata.Attribute.merge/4
       (speck 4.0.0) lib/speck/validation_metadata/attribute.ex:46: Speck.ValidationMetadata.Attribute.merge/4
       (speck 4.0.0) lib/speck/validation_metadata/attribute.ex:65: Speck.ValidationMetadata.Attribute.merge/4
       (speck 4.0.0) lib/speck/validation_metadata/attribute.ex:75: Speck.ValidationMetadata.Attribute.merge/4
       (elixir 1.18.3) lib/enum.ex:2546: Enum."-reduce/3-lists^foldl/2-0-"/3
       test/validation_metadata/attribute_test.exs:23: (test)

@amclain amclain self-assigned this Dec 4, 2025
@amclain amclain added the defect label Dec 4, 2025
@amclain amclain merged commit b92a43b into main Dec 4, 2025
2 checks passed
@amclain amclain deleted the fix/merge-nested-list branch December 4, 2025 05:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants