Skip to content

array(:hash) not validating a filter #448

Open
@ritxi

Description

@ritxi

Describe the bug

I have the following schema that works in isolation, but not inside an array(:hash) with a required field with a filter that won't work

To Reproduce

# Working in isolation
schema = Dry::Schema.Params do
    required(:date).filter { 
      format?(%r[\d{2}/\d{2}/\d{4}])
    }.value(:date)
end

schema.call(id: 'foo', date: '2022/05/02')

#<Dry::Schema::Result{:date=>"2022/05/02"} errors={:date=>["is in invalid format"]} path=[]>

# Not working when inside `array(:hash)`

schema = Dry::Schema.Params do
  required(:group).array(:hash) do
    required(:id).value(:integer)
    required(:date).filter { 
      format?(%r[\d{2}/\d{2}/\d{4}])
    }.value(:date)
  end
end
schema.call(group: [{id: 1, date: '2022/05/02'}])

#<Dry::Schema::Result{:group=>[{:id=>1, :date=>Mon, 02 May 2022}]} errors={} path=[]>

Expected behavior

I expect filter validation to work

#<Dry::Schema::Result{:group=>[{:id=>1, :date=>"2022/05/02"}]} errors={:group=>{0=>{:date=>["is in invalid format"]}}} path=[]>

My environment

  • Affects my production application: NO
  • Ruby version: 2.7.6
  • OS: Debian Bullseye (Docker image ruby:2.7.6)

Metadata

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