Attribute set Rails relation validators cause discovery to fail
The initial discovery upload fails with 422 ActiveRecord::RecordNotSaved: Failed to save the new associated discovery_attribute_set. The problem is that Rails presence validator errors out when host_id is not set when discovered host is not yet saved. This happens because update call calls save when host_id is not yet set.
As a consequence, discovery_attribute_set is not set however discovered host is saved with null reference, therefore subsequent discovery fact upload already has host.id set therefore this should save. Unfortunately due to the other validator (
:discovery_attribute_set, :presence => true) it won't because then it fails with a different error 422 Validation failed: Discovery attribute set can't be blank.
This patch removes the unnecessary validators because the code is ready today that attributes association can be blank. This was added because when discovery fails, it is set to blank anyway. This could be prevented by utilizing SQL transactions, however we've been there and it caused huge pains in our orchestration and it was reverted. I left a note about this in the codebase.
#3 Updated by Anonymous about 1 year ago
- Status changed from Ready For Testing to Closed
Applied in changeset foreman_discovery|daaa178a3eed78d5fa777e32edcc0d5bdf2a3871.