You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey all, first of all thanks for the great library, we're using this gem a lot (alongside a variety of other tools from the dry-rb ecosystem) and find it super-useful 🎉 . Thank you all for the work you're putting into these great tools!
Describe the bug
I have encountered a very strange behaviour when dealing with validations on hashes inside an array, where the nested datetime fails to validate, whereas the same rule at the top level works just fine.
To Reproduce
require"pp"require"dry-validation"moduleTypesincludeDry.Types(default: :nominal)endclassHmm < Dry::Validation::Contractparamsdooptional(:works_at).filled(Types::Params::DateTime)optional(:widgets).maybe(:array).eachdohashdooptional(:fails_at).filled(Types::Params::DateTime)endendendendppHmm.new.call(works_at: Time.now.iso8601,widgets: [{fails_at: Time.now.iso8601}]).errors.to_h# => {:widgets=>{0=>{:fails_at=>["must be a date time"]}}}
Expected behavior
The example above should be valid, but is not. I also tried experimenting with a variety of other types but all have the same issue.
My environment
Affects my production application: YES (such that I cannot make valid parameters pass through my contract)
Ruby version: 3.2.2
OS: Linux
dry-validation 1.10.0 (latest)
dry-schema 1.13.3 (latest)
dry-types 1.7.1 (latest)
The text was updated successfully, but these errors were encountered:
On another note, I attempted to make a workaround using a complex dry-type instead of the contracts DSL, but this actually runs into the same issue as well
classHmm < Dry::Validation::Contractparamsdooptional(:works_at).filled(Types::Params::DateTime)TYPE=Types::Strict::Array.of(Types::Hash.schema(fails_at: Types::Params::DateTime))optional(:widgets).maybe(TYPE)endendppHmm.new.call(works_at: Time.now.iso8601,widgets: [{fails_at: Time.now.iso8601}]).errors.to_h# => {:widgets=>{0=>{:fails_at=>["must be a date time"]}}}
The only way I can get this to work is to skip the iso8601 parsing part and use Types::Params::Time and pass Time.now instead, but that's kinda missing the point because I want to return structured errors when a user submits an invalid timestamp
I came up with a way how to work around this issue, by making my nested date time a string on the contract and then performing the type casting and param validation myself in a rule. This then yields the desired result:
Hey all, first of all thanks for the great library, we're using this gem a lot (alongside a variety of other tools from the dry-rb ecosystem) and find it super-useful 🎉 . Thank you all for the work you're putting into these great tools!
Describe the bug
I have encountered a very strange behaviour when dealing with validations on hashes inside an array, where the nested datetime fails to validate, whereas the same rule at the top level works just fine.
To Reproduce
Expected behavior
The example above should be valid, but is not. I also tried experimenting with a variety of other types but all have the same issue.
My environment
The text was updated successfully, but these errors were encountered: