Bug #27340
closedAttribute set Rails relation validators cause discovery to fail
Description
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.
Updated by The Foreman Bot over 5 years ago
- Status changed from New to Ready For Testing
- Pull request https://github.com/theforeman/foreman_discovery/pull/482 added
Updated by The Foreman Bot over 5 years ago
- Fixed in Releases Discovery Plugin 16.0 added
Updated by Anonymous over 5 years ago
- Status changed from Ready For Testing to Closed
Applied in changeset foreman_discovery|daaa178a3eed78d5fa777e32edcc0d5bdf2a3871.
Updated by Lukas Zapletal over 5 years ago
- Target version changed from Discovery Plugin 16.0 to Discovery Plugin 15.0
- Fixed in Releases Discovery Plugin 15.0.1 added
- Fixed in Releases deleted (
Discovery Plugin 16.0)
Updated by The Foreman Bot over 5 years ago
- Pull request https://github.com/theforeman/foreman_discovery/pull/484 added
Updated by The Foreman Bot over 5 years ago
- Pull request https://github.com/theforeman/foreman_discovery/pull/488 added