Skip to content

Unexpected behaviour with array of hashes #410

Open
@jmortlock

Description

Describe the bug

Reusing a schema directly in the the array macro produces an unexpected exception when passed bad data.

To Reproduce

NestedHash = Dry::Schema.Params {
  required(:code).filled(:string)
}

Parent = Dry::Schema.Params {
 required(:nested).array(NestedHash)
}

## Exception
result = Parent.call(nested: [[]])
/vendor/ruby/3.0.0/gems/dry-logic-1.2.0/lib/dry/logic/predicates.rb:25:in `key?': undefined method `key?' for []:Array (NoMethodError)

If you correctly pass it in an array of hashes it will happily work

Expected behavior

Should work the same as the long form expression; or not work at all.

Parent = Dry::Schema.Params {
  required(:nested).array(:hash).each(NestedHash)
}
result = Parent.call(nested: [[]])

My environment

Running the latest and greatest versions of dry-schema (1.9.2)

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions