# Dry-struct missing attribute and maybe type

**URL:** <https://discourse.dry-rb.org/t/dry-struct-missing-attribute-and-maybe-type/1198>\
**Category:** Support\
**Created:** [February 9, 2021, 3:06am UTC](https://discourse.dry-rb.org/t/dry-struct-missing-attribute-and-maybe-type/1198 "2021-02-09T03:06:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DawidJanczak](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/dawidjanczak/32/261_2.png) [@DawidJanczak](https://discourse.dry-rb.org/u/DawidJanczak)\
**Post date:** [February 9, 2021, 3:06am UTC](https://discourse.dry-rb.org/t/dry-struct-missing-attribute-and-maybe-type/1198/1 "2021-02-09T03:06:58Z")

</div>

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](https://github.com/DawidJanczak/dry-struct-maybe-attribute-oddity/blob/master/test.rb) 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`.

---

<div class="post-metadata">

**Author:** ![solnic](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/solnic/32/779_2.png) [@solnic](https://discourse.dry-rb.org/u/solnic)\
**Post date:** [February 9, 2021, 5:36am UTC](https://discourse.dry-rb.org/t/dry-struct-missing-attribute-and-maybe-type/1198/2 "2021-02-09T05:36:15Z")

</div>

@DawidJanczak this is a bug. please report an issue 🙇‍♂️

---

<div class="post-metadata">

**Author:** ![DawidJanczak](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/dawidjanczak/32/261_2.png) [@DawidJanczak](https://discourse.dry-rb.org/u/DawidJanczak)\
**Post date:** [February 9, 2021, 5:52am UTC](https://discourse.dry-rb.org/t/dry-struct-missing-attribute-and-maybe-type/1198/3 "2021-02-09T05:52:57Z")

</div>

Thank you, reported under [Missing attribute and maybe type · Issue #166 · dry-rb/dry-struct · GitHub](https://github.com/dry-rb/dry-struct/issues/166)
