Dry-struct missing attribute and maybe type

Hello!

I ran into a weird bug today with dry-struct and a maybe attribute. I put up a running example here dry-struct-maybe-attribute-oddity/test.rb at master · DawidJanczak/dry-struct-maybe-attribute-oddity · GitHub To summarise: when I have a field that’s required, but its value is a maybe (attribute :missing, Types::String.maybe in the example) not passing that field does not fail when I create an object with that attribute missing, but it does fail later. In our case it fails when we call as_json on the resulting struct, but the error itself seems to be coming from dry-types so I suspect this isn’t the only scenario when this would fail. I wonder if creating a struct should fail in this case in the same way it does when we don’t use maybe.

@DawidJanczak this is a bug. please report an issue :bowing_man:

Thank you, reported under Missing attribute and maybe type · Issue #166 · dry-rb/dry-struct · GitHub

1 Like