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

Validation errors are added twice in the model.errors array #69

Open
mtaylor opened this issue Dec 11, 2012 · 1 comment
Open

Validation errors are added twice in the model.errors array #69

mtaylor opened this issue Dec 11, 2012 · 1 comment
Assignees

Comments

@mtaylor
Copy link

mtaylor commented Dec 11, 2012

The issue bellow is probably related to the commit which adds validations in combination with "inverse_of". The problem is that when importing an image (with some invalid fields, e.g. base image's name), validations are done mutliple times. You can reproduce with following code:

irb(main):004:0> x = Tim::BaseImage.new("pool_family_id"=>"1", "import"=>"true", "image_versions_attributes"=>{"0"=>{"target_images_attributes"=>{"0"=>{"provider_images_attributes"=>{"0"=>{"provider_account_id"=>"2", "external_image_id"=>""}}}}}}, "name"=>"")
irb(main):005:0> x.valid?
=> false
irb(main):007:0> x.errors.full_messages
=> ["Name can't be blank", "Name can't be blank", "Image versions base image name can't be blank", "Image versions target images image version base image name can't be blank", "Image versions target images target can't be blank", "Image versions target images provider images target image image version base image name can't be blank", "Image versions target images provider images target image target can't be blank", "Image versions target images provider images external image can't be blank"]

@ghost ghost assigned mtaylor Dec 11, 2012
@mtaylor
Copy link
Author

mtaylor commented Dec 12, 2012

This issue is indeed caused by the inverse_of vs accepts_nested_attributes bug that currently have a patch for. Unfortunatley the patch does not cover duplicate validations which is what we are seeing here.

For the time being Jan has agreed to fix this in conductor. I am hoping this will be fixed soon in Rails. This is another case for not using accpets_nested_attributes_for in models. I am starting to think that creating our own gem for generating nested objects from hash maps is the way forward.

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

1 participant