Bug #36753
closedPG::UniqueViolation on index_cve_cp_id during registration
Description
I hit the following when registering a host AND setting a the lifecycle environment on the "Advanced" tab of Global Registration:
2023-09-15T20:17:26 [I|app|29348cd9] ContentViewEnvironment not found for content view 'Default Organization View' and environment 'Precipitation'; creating a new one.
2023-09-15T20:17:26 [W|app|29348cd9] Action failed
2023-09-15T20:17:26 [I|app|29348cd9] Backtrace for 'Action failed' error (ActiveRecord::RecordNotUnique): PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_cve_cp_id"
29348cd9 | DETAIL: Key (cp_id)=(64c2cce3716a5bf67b0413fac95e5daa) already exists.
29348cd9 |
29348cd9 | /home/vagrant/foreman/.vendor/ruby/2.7.0/gems/activerecord-6.1.7.6/lib/active_record/connection_adapters/postgresql_adapter.rb:672:in `exec_params'
...
29348cd9 | /home/vagrant/foreman/.vendor/ruby/2.7.0/gems/activerecord-6.1.7.6/lib/active_record/relation.rb:99:in `create'
29348cd9 | /home/vagrant/foreman/.vendor/ruby/2.7.0/gems/activerecord-6.1.7.6/lib/active_record/relation.rb:119:in `first_or_create'
29348cd9 | /home/vagrant/katello/app/models/katello/host/content_facet.rb:117:in `assign_single_environment'
29348cd9 | /home/vagrant/katello/app/controllers/katello/concerns/api/v2/registration_controller_extensions.rb:22:in `host_setup_extension'
29348cd9 | /home/vagrant/foreman/app/controllers/api/v2/registration_controller.rb:81:in `block in host'
The line of code in question is here: https://github.com/Katello/katello/commit/c33da7a3fa9473add44a154feba4e57f34b2b289#diff-ba6065a40faacc57174e6322ee3eab19b4771a0e9cf91efdc6b60d9f8b951646R101
In my database, I see:
[2] pry(main)> ::Katello::ContentViewEnvironment.where(cp_id: '64c2cce3716a5bf67b0413fac95e5daa')
=> [#<Katello::ContentViewEnvironment:0x000055b36b48b678
id: 1,
name: "Library",
label: "Library",
cp_id: "64c2cce3716a5bf67b0413fac95e5daa",
content_view_id: 1,
created_at: Wed, 23 Aug 2023 19:53:27.763161000 UTC +00:00,
updated_at: Wed, 23 Aug 2023 19:53:27.763161000 UTC +00:00,
environment_id: 1,
content_view_version_id: 1>]
Registering the host works only if I don't specify the lifecycle environment.
Tested on master as of Sept 15, 2023
Updated by Ian Ballou about 1 year ago
Perhaps relevant -- I was using a Library activation key, but chose a different LCE on the Advanced tab.
If this is the cause, perhaps we can remove the lifecycle environment selection entirely. Activation keys are required anyway.
Updated by Ian Ballou about 1 year ago
Jeremy found some new info:
In content_view_environment.rb here's the way we generate the CVE's cp_id:
def generate_info
self.name ||= environment.name
if content_view.default?
self.label ||= environment.label
self.cp_id ||= Katello::Util::Data.hexdigest(environment.organization.label)
else
self.label ||= [environment.label, content_view.label].join('/')
self.cp_id ||= Katello::Util::Data.hexdigest([environment.id, content_view.id].join('-'))
end
end
because I was essentially trying to subscribe to Default Organization View / <Non-Library LCE> , `content_view.default?` returns true and causes mayhem.
A nicer error should be returned here. Plus, we should fix the UI.
Updated by Lucy Fu about 1 year ago
- Target version set to Katello 4.11.0
- Triaged changed from No to Yes
Updated by The Foreman Bot about 1 year ago
- Status changed from New to Ready For Testing
- Assignee set to Jeremy Lenz
- Pull request https://github.com/Katello/katello/pull/10764 added
Updated by The Foreman Bot about 1 year ago
- Fixed in Releases Katello 4.11.0 added
Updated by Jeremy Lenz about 1 year ago
- Status changed from Ready For Testing to Closed
Applied in changeset katello|337b5d6163d324ad601a4165e90dae7de4779392.