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

since 2.3.0rc1, unnested properties error on validate when parent property is nil #433

Open
lastobelus opened this issue May 17, 2017 · 1 comment
Milestone

Comments

@lastobelus
Copy link

Since the upgrade to 2.3.0rc1, unnested properties cause an error on validate when the parent property is nil, which was not the case in 2.2.0. Is this intended? Is there any workaround?

Steps to reproduce

class VendorLineItemForm < Reform::Form
  property :line_item_id
  property :vendor_fulfillment do
    property :fulfillment_service_id
  end
  unnest :fulfillment_service_id, from: :vendor_fulfillment
end

This form is used as the item form for a collection property in another form, which has a populator that finds or creates a vendor_fulfillment for the incoming fulfillment_service_id, using nil if it can't find one or fulfillment_service_id is nil, and then uses it in a VendorLineItem.

Now, I don't actually want vendor_fulfillment to be nil, and I have validation that verifies that it is not and that the fulfillment_service_id belongs to a scoped set of ids.

This worked in 2.2.0, but after upgrading to 2.3.0rc1 it raises after population has run but before it gets to my validation:

       undefined method `fulfillment_service_id' for nil:NilClass
     # representable-3.0.4/lib/representable/serializer.rb:6:in `public_send'
     # representable-3.0.4/lib/representable/serializer.rb:6:in `block in <module:Representable>'
     # representable-3.0.4/lib/representable/pipeline.rb:18:in `evaluate'
     # representable-3.0.4/lib/representable/pipeline.rb:10:in `block in call'
     # representable-3.0.4/lib/representable/pipeline.rb:9:in `each'
     # representable-3.0.4/lib/representable/pipeline.rb:9:in `inject'
     # representable-3.0.4/lib/representable/pipeline.rb:9:in `call'
     # representable-3.0.4/lib/representable/binding.rb:32:in `compile_fragment'
     # representable-3.0.4/lib/representable.rb:53:in `block in call'
     # representable-3.0.4/lib/representable.rb:51:in `each'
     # representable-3.0.4/lib/representable.rb:51:in `call'
     # representable-3.0.4/lib/representable.rb:70:in `representable_map!'
     # representable-3.0.4/lib/representable.rb:45:in `create_representation_with'
     # representable-3.0.4/lib/representable/hash.rb:34:in `to_hash'
     # reform-0753ac23c0aa/lib/reform/form/dry.rb:76:in `input_hash'
     # reform-0753ac23c0aa/lib/reform/form/dry.rb:50:in `call'
     # reform-0753ac23c0aa/lib/reform/validation/groups.rb:48:in `block in call'
     # reform-0753ac23c0aa/lib/reform/validation/groups.rb:45:in `collect'
     # reform-0753ac23c0aa/lib/reform/validation/groups.rb:45:in `call'
     # reform-0753ac23c0aa/lib/reform/contract/validate.rb:27:in `validate!'
     # reform-0753ac23c0aa/lib/reform/contract/validate.rb:52:in `block (2 levels) in validate_nested!'
     # disposable-0.4.3/lib/disposable/twin/property_processor.rb:24:in `block in collection!'
     # disposable-0.4.3/lib/disposable/twin/property_processor.rb:24:in `each'
     # disposable-0.4.3/lib/disposable/twin/property_processor.rb:24:in `each_with_index'
     # disposable-0.4.3/lib/disposable/twin/property_processor.rb:24:in `each'
     # disposable-0.4.3/lib/disposable/twin/property_processor.rb:24:in `collect'
     # disposable-0.4.3/lib/disposable/twin/property_processor.rb:24:in `collection!'
     # disposable-0.4.3/lib/disposable/twin/property_processor.rb:16:in `call'
     # reform-0753ac23c0aa/lib/reform/contract/validate.rb:49:in `block in validate_nested!'
     # disposable-0.4.3/lib/disposable/twin/definitions.rb:27:in `block in each'
     # disposable-0.4.3/lib/disposable/twin/definitions.rb:27:in `each'
     # disposable-0.4.3/lib/disposable/twin/definitions.rb:27:in `each'
     # reform-0753ac23c0aa/lib/reform/contract/validate.rb:47:in `validate_nested!'
     # reform-0753ac23c0aa/lib/reform/contract/validate.rb:33:in `validate!'
     # reform-0753ac23c0aa/lib/reform/contract/validate.rb:11:in `validate'
     # reform-0753ac23c0aa/lib/reform/form/validate.rb:24:in `validate'

is there a workaround, or do I always have to create an empty VendorFulfillment in my populator if I want to use unnest on its properties?

@fran-worley
Copy link
Collaborator

This looks as if it's an issue with the to_hash method in representable being called from here - https://github.com/trailblazer/reform/blob/master/lib/reform/form/dry.rb#L76

@apotonick any suggestions on how Representable could return nil instead of raise an error in these cases?

@emaglio emaglio added this to the v 2.3 milestone Jul 12, 2019
@emaglio emaglio modified the milestones: v 2.3, 3.0 Nov 10, 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

3 participants