dry-rb / dry-schema

Coercion and validation for data structures
https://dry-rb.org/gems/dry-schema
MIT License
421 stars 110 forks source link

Schema definition regression after 1.9.3 #438

Closed pyromaniac closed 1 year ago

pyromaniac commented 1 year ago

Hello there folks!

Describe the bug

There was a weird schema regression after 1.9.3.

To Reproduce

s = Dry::Schema.Params do
  optional(:review).maybe(:hash) do
    required(:rating).filled(:decimal)
    optional(:comment).maybe(:string)
  end
end
s.call(review: { rating: 3 })
#=> #<Dry::Schema::Result{:review=>{:rating=>3}} errors={:review=>{:rating=>["must be a decimal"]}} path=[]>

Unfortunately, unable to debug it deeper but .maybe(:hash) is important and optional(:comment).maybe(:string) presence is also important. It could be some leakage in the schema definition.

Expected behavior

In 1.9.3 it works as expected passing the validation.

My environment

Big thank you in advance!

flash-gordon commented 1 year ago

At the first glance this is connected https://github.com/dry-rb/dry-validation/issues/718 😅

pyromaniac commented 1 year ago

It indeed looks the same issue. I also had a bigger schema and managed to reduce the example to the one I submitted and it looks very similar to https://github.com/dry-rb/dry-validation/issues/718#issuecomment-1284124753

solnic commented 1 year ago

I'll look into this. Most likely it's the same story as with #437.