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

Open
pricelessrabbit opened this issue Jul 27, 2021 · 0 comments · May be fixed by #177
Open

MissingAttributeError when access optional field with hash syntax #171

pricelessrabbit opened this issue Jul 27, 2021 · 0 comments · May be fixed by #177

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
ivleonov added a commit to ivleonov/dry-struct that referenced this issue Nov 29, 2021
@ivleonov ivleonov linked a pull request Nov 29, 2021 that will close this issue
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