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

Undefined method visit_d for an "optional" validation #386

Closed
solnic opened this issue Feb 2, 2018 · 4 comments
Closed

Undefined method visit_d for an "optional" validation #386

solnic opened this issue Feb 2, 2018 · 4 comments

Comments

@solnic
Copy link
Member

solnic commented Feb 2, 2018

From @chikamichi on December 15, 2016 11:5

Hi,

Using dry-types 0.9.3 through dry-validation, this simple rule:

optional('draft').maybe(:str?)

triggers:

/var/lib/gems/2.2.0/gems/dry-types-0.9.3/lib/dry/types/compiler.rb:15:in `visit': undefined method `visit_d' for #<Dry::Types::Compiler:0x000000055df778 @registry=Dry:
:Types> (NoMethodError)
        from /var/lib/gems/2.2.0/gems/dry-types-0.9.3/lib/dry/types/compiler.rb:35:in `block in visit_sum'
        from /var/lib/gems/2.2.0/gems/dry-types-0.9.3/lib/dry/types/compiler.rb:35:in `map'
        from /var/lib/gems/2.2.0/gems/dry-types-0.9.3/lib/dry/types/compiler.rb:35:in `visit_sum'
        from /var/lib/gems/2.2.0/gems/dry-types-0.9.3/lib/dry/types/compiler.rb:15:in `visit'
        from /var/lib/gems/2.2.0/gems/dry-types-0.9.3/lib/dry/types/compiler.rb:80:in `block in merge_with'
        from /var/lib/gems/2.2.0/gems/dry-types-0.9.3/lib/dry/types/compiler.rb:80:in `map'
        from /var/lib/gems/2.2.0/gems/dry-types-0.9.3/lib/dry/types/compiler.rb:80:in `merge_with'
        from /var/lib/gems/2.2.0/gems/dry-types-0.9.3/lib/dry/types/compiler.rb:52:in `visit_hash'
        from /var/lib/gems/2.2.0/gems/dry-types-0.9.3/lib/dry/types/compiler.rb:28:in `visit_type'
        from /var/lib/gems/2.2.0/gems/dry-types-0.9.3/lib/dry/types/compiler.rb:15:in `visit'
        from /var/lib/gems/2.2.0/gems/dry-types-0.9.3/lib/dry/types/compiler.rb:11:in `call'
        from /var/lib/gems/2.2.0/gems/dry-validation-0.10.4/lib/dry/validation/input_processor_compiler.rb:16:in `call'
        from /var/lib/gems/2.2.0/gems/dry-validation-0.10.4/lib/dry/validation/schema/deprecated.rb:14:in `input_processor'
        from /var/lib/gems/2.2.0/gems/dry-validation-0.10.4/lib/dry/validation/schema/class_interface.rb:163:in `default_options'
        from /var/lib/gems/2.2.0/gems/dry-validation-0.10.4/lib/dry/validation/schema/class_interface.rb:34:in `new'
        from /var/lib/gems/2.2.0/gems/dry-validation-0.10.4/lib/dry/validation.rb:26:in `Schema'

Nothing fancy about the way I use dry-validation here. required works just fine, the error only gets triggered by optional with a block, therefore I suspect either visit_sum to be doing something wrong, or what's fed to visit_sum to be incorrect.

Copied from original issue: dry-rb/dry-types#172

@solnic
Copy link
Member Author

solnic commented Feb 2, 2018

From @chikamichi on December 16, 2016 12:24

I've found that the error only occurs when activating dry-validation's sanitizer (config.input_processor = :sanitizer). Let me know if you'd like me to report the bug on the dry-validation issue tracker instead.

@solnic
Copy link
Member Author

solnic commented Feb 2, 2018

From @flash-gordon on February 1, 2018 23:17

I'll close this issue since it's on the dry-v side mostly. We are working on dry-validation 1.0, it's going to take a while but we hope to push a beta in two to three months (optimistic mode on). It's probably a good idea to check if this will work fine there so pls bring this issue to dry-validation's repo.

@mtomov
Copy link

mtomov commented Feb 16, 2018

Can confirm the issue. Thanks!

indrekj added a commit to indrekj/dry-validation that referenced this issue Sep 26, 2018
Previously using `optional('height').filled` produced
```
  NoMethodError:
    undefined method `visit_height' for #<Dry::Types::Compiler:0x007fdf3f9eb530 @registry=Dry::Types>
```
when the input_processor was set to sanitizer.

Input processor compiler was checking only if the key was a symbol. Now
it also checks for string keys.

Fixes dry-rb#386
@solnic
Copy link
Member Author

solnic commented Feb 5, 2019

Closing because this works fine in dry-schema.

@solnic solnic closed this as completed Feb 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants