Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MissingAttributeError when access optional field with hash syntax #171

Closed
pricelessrabbit opened this issue Jul 27, 2021 · 0 comments
Closed

Comments

@pricelessrabbit
Copy link

I all :) hope it is the right place to post.

Describe the bug

i tried to access struct attributes using the hash syntax and i found out different behaviour when access optional field in struct using method (struct.field) and hash (struct[:field]).
Is this the intended behaviour or a bug?

To Reproduce

class MyStuct < Dry::Struct
   transform_keys(&:to_sym)
   attribute? :my_attribute, Dry::Types::Integer.optional
end

Expected behavior

s = MyStruct.new
s.my_attribute # nil
s[:my_attribute] # nil

Actual behavior

s = MyStruct.new
s.my_attribute # nil
s[:my_attribute] #MissingAttributeError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant