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
When I have a field that’s required, but its value is a maybe (attribute :missing, Types::String.maybefor 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 callas_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'm not sure I follow, dry-struct doesn't define as_json, why should it care? Serializing to JSON is not part of the gem and I'm against mixing concerns in general.
Describe the bug
When I have a field that’s required, but its value is a maybe (attribute :missing, Types::String.maybe
for 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.To Reproduce
Reproducible script can be found under https://github.com/DawidJanczak/dry-struct-maybe-attribute-oddity/blob/master/test.rb
Expected behavior
Either instantiating a struct should fail earlier (this would be a potentially breaking change) or
as_json
should work as expected.My environment
Linux hp 5.10.11-arch1-1 #1 SMP PREEMPT Wed, 27 Jan 2021 13:53:16 +0000 x86_64 GNU/Linux
The text was updated successfully, but these errors were encountered: