Description of problem: Add same policy twice to any host using bulk action fails with sql error, here is traceback ~~~ 2020-07-30T10:02:15 [I|app|7234a419] Started POST "/compliance/policies/update_multiple_hosts?host_ids%5B%5D=4&host_ids%5B%5D=1" for 127.0.0.1 at 2020-07-30 10:02:15 -0400 2020-07-30T10:02:15 [I|app|7234a419] Processing by PoliciesController#update_multiple_hosts as HTML 2020-07-30T10:02:15 [I|app|7234a419] Parameters: {"utf8"=>"✓", "authenticity_token"=>"AsoqhvaapVoYTBwMLIox+2ICKHwvMRV3jjSP0T103oDAJKw954AF0pszr5CazvCF26e9ttVLQUIplONSx6IkGA==", "policy"=>{"id"=>"1"}, "host_ids"=>["4", "1"]} 2020-07-30T10:02:17 [D|tax|7234a419] Current location set to Default Location 2020-07-30T10:02:17 [D|tax|7234a419] Current organization set to Default Organization 2020-07-30T10:02:17 [W|app|7234a419] Action failed 2020-07-30T10:02:17 [D|app|7234a419] Backtrace for 'Action failed' error (ActiveRecord::RecordNotUnique): PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_scaptimony_asset_policies_on_asset_id_and_policy_id" DETAIL: Key (asset_id, policy_id)=(8, 1) already exists. /opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/postgresql_adapter.rb:675:in `async_exec_params' /opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/postgresql_adapter.rb:675:in `block (2 levels) in exec_no_cache' /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.1/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads' /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.1/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares' /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.1/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads' /opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/postgresql_adapter.rb:674:in `block in exec_no_cache' /opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_adapter.rb:722:in `block (2 levels) in log' ~~~ Version-Release number of selected component (if applicable): Satellite 6.8 How reproducible: Always Steps to Reproduce: 1. Go To "All Hosts" 2. select few Hosts -> Click on "Select Action" on top right and click on "Assign Compliance Policy" 3. Select First Policy and click on submit 4. Repeat same step i.e select same hosts and try to assign same policy Actual results: It should not fails with sql error. Expected results: It should ignore the host if same epolicy is already assign Additional info:
Created redmine issue https://projects.theforeman.org/issues/30536 from this bug
Upstream bug assigned to oprazak
Moving this bug to POST for triage into Satellite since the upstream issue https://projects.theforeman.org/issues/30536 has been resolved.
Verified Verified with: - Satellite 6.8.0 snap 12 Test steps: 1. Create a compliance policy 2. Go to Hosts > All Hosts page 3. Select few hosts and assign compliance policy. 4. Select same hosts and same assign compliance policy again. Observations: - No sql errors. - compliance policy applied successfully.
Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory (Important: Satellite 6.8 release), and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. https://access.redhat.com/errata/RHSA-2020:4366