Bug #38819
closedCouldn't find User with 'id'=9 HTTP error code 404: Not Found when trying to register any host
Description
This only happens when host_owner setting is set to a default value i.e. a specific user but that user has been deleted from the database.
To say it in the other way, if a user was set as the host_owner in settings, when we delete the user from webui or hammer, the `host_owner` setting is not unset and that leads to this issue.
Steps:
1. Create a user and give it admin rights
2. Set the user as the `Host owner` in the settings
3. Generate a command to register a system
4. Delete the user with hammer or webui
5. Try registering a host with the generated curl command
Actual:
2025-05-21T18:48:37 [E|kat|6cfd385b] ActiveRecord::RecordNotFound: Couldn't find User with 'id'=9 [WHERE (users.id IN (8,1,2,5,3,4,7,6,2,8,4,1,3,1))]
6cfd385b | /usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/relation/finder_methods.rb:357:in `raise_record_not_found_exception!'
6cfd385b | /usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/relation/finder_methods.rb:476:in `find_one'
6cfd385b | /usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/relation/finder_methods.rb:458:in `find_with_ids'
6cfd385b | /usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/relation/finder_methods.rb:69:in `find'
6cfd385b | /usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/querying.rb:22:in `find'
6cfd385b | /usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/core.rb:340:in `find'
6cfd385b | /usr/share/foreman/app/services/owner_classifier.rb:12:in `classify_owner'
6cfd385b | /usr/share/foreman/app/models/concerns/hostext/ownership.rb:47:in `owner_suggestion'
6cfd385b | /usr/share/foreman/app/models/concerns/hostext/ownership.rb:67:in `set_default_user'
..
..
6cfd385b | /usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/transactions.rb:302:in `save!'
6cfd385b | /usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/suppressor.rb:48:in `save!'
6cfd385b | /usr/share/gems/gems/katello-4.14.0.12/app/services/katello/registration_manager.rb:180:in `register_host'
6cfd385b | /usr/share/gems/gems/katello-4.14.0.12/app/services/katello/registration_manager.rb:36:in `process_registration'
Expected:
When deleting a user, it should check all the relevant associations with the user and unset them e.g. Host Owner settings in this case.
Updated by The Foreman Bot 4 months ago
- Status changed from Assigned to Ready For Testing
- Pull request https://github.com/theforeman/foreman/pull/10719 added
Updated by Oleh Fedorenko 4 months ago
- Status changed from Ready For Testing to Closed
Applied in changeset foreman|a11563ae4e4c1db18262c02e9792b3d353400fbf.
Updated by Ondřej Gajdušek 3 months ago
- Subject changed from Couldn't find User with 'id'=9 HTTP error code 404: Not Found when trying to register any system to Couldn't find User with 'id'=9 HTTP error code 404: Not Found when trying to register any host