[Satellite6] An error occurred saving the Repository: undefined method `content_id' for nil:NilClass Did you mean? contains_erb?

Solution Verified - Updated

Environment

Satellite 6.4 or newer

Issue

When trying to save changes done to a custom repository an error is displayed in the webui:

An error occurred saving the Repository: undefined method `content_id' for nil:NilClass Did you mean? contains_erb?

The repository update task fails

Actions::Katello::Repository::Update

undefined method `content_id' for nil:NilClass
Did you mean?  contains_erb? (NoMethodError)
/opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.7.0.46/app/lib/actions/katello/repository/update.rb:15:in `plan'
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.0.5.5/lib/dynflow/action.rb:493:in `block (3 levels) in execute_plan'
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.0.5.5/lib/dynflow/middleware/stack.rb:26:in `pass'
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.0.5.5/lib/dynflow/middleware.rb:18:in `pass'
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-0.13.4.3/app/lib/actions/middleware/keep_current_user.rb:10:in `block in plan'
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-0.13.4.3/app/lib/actions/middleware/keep_current_user.rb:31:in `with_current_user'
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-0.13.4.3/app/lib/actions/middleware/keep_current_user.rb:9:in `plan'
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.0.5.5/lib/dynflow/middleware/stack.rb:22:in `call'
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.0.5.5/lib/dynflow/middleware/stack.rb:26:in `pass'
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.0.5.5/lib/dynflow/middleware.rb:18:in `pass'
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.0.5.5/lib/dynflow/middleware.rb:35:in `plan'
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.0.5.5/lib/dynflow/middleware/stack.rb:22:in `call'
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.0.5.5/lib/dynflow/middleware/stack.rb:26:in `pass'
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.0.5.5/lib/dynflow/middleware.rb:18:in `pass'
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.0.5.5/lib/dynflow/middleware.rb:35:in `plan'
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.0.5.5/lib/dynflow/middleware/stack.rb:22:in `call'
  • The error can also be:
undefined method `name' for nil:NilClass (NoMethodError)
/opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.10.0.58/app/lib/actions/katello/repository/update.rb:18:in `plan'
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.1.6.1/lib/dynflow/action.rb:493:in `block (3 levels) in execute_plan'
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.1.6.1/lib/dynflow/middleware/stack.rb:26:in `pass'
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.1.6.1/lib/dynflow/middleware.rb:18:in `pass'
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.1.6.1/lib/dynflow/middleware.rb:35:in `plan'

Resolution

Re-create the task again

#foreman-rake console
r = Katello::Repository.where(pulp_id: '1-rhelrepo-v1_0-15c2da4e-8d96-4d75-af1a-ff3bc7edb4ea').order(:id).first
ForemanTasks.async_task(Actions::Katello::Repository::Create, r)

For more KB articles/solutions related to Red Hat Satellite 6.x Repository Issues, please refer to the Red Hat Satellite Consolidated Troubleshooting Article for Red Hat Satellite 6.x Repository Issues.

Root Cause

An entry was missing in the foreman database in katello_contents table.

Diagnostic Steps

verify the `katello_contents` table data

foreman=# select * from katello_contents where name like '%okrepo%';
-[ RECORD 1 ]---+-------------------------------------------------------
id              | 222
cp_content_id   | 1234494940257
content_type    | yum
name            | okrepo
label           | okrepo
vendor          | Custom
gpg_url         | ../../katello/api/v2/repositories/3221/gpg_key_content
content_url     | /custom/customrepos/okrepos
organization_id | 1

select * from katello_contents where name like '%brokenrepo%';
(No rows)

but it is present in the katello_repositories table

foreman=# select * from katello_repositories where pulp_id = '1-rhelrepo-v1_0-15c2da4e-8d96-4d75-af1a-ff3bc7edb4ea';
-[ RECORD 1 ]---------------+-------------------------------------------------------------------------------------
id                          | 1234
name                        | brokenrepo
pulp_id                     | 1-rhelrepo-v1_0-15c2da4e-8d96-4d75-af1a-ff3bc7edb4ea
created_at                  | 2019-02-05 21:11:32.937125
updated_at                  | 2019-02-05 21:11:32.937125
major                       | 
minor                       | 
gpg_key_id                  | 
cp_label                    | 
library_instance_id         | 1222
content_id                  | 1543494961803
arch                        | noarch
label                       | brokenrepo
content_view_version_id     | 150
relative_path               | custom/customrepos/rhelrepo/1.0/custom/Custom/brokenrepo
url                         | 
unprotected                 | t
content_type                | yum
product_id                  | 99
environment_id              | 
checksum_type               | 
docker_upstream_name        | 
distribution_version        | 
distribution_arch           | 
distribution_bootable       | 
distribution_family         | 
distribution_variant        | 
distribution_uuid           | 
mirror_on_sync              | t
download_policy             | on_demand
verify_ssl_on_sync          | t
upstream_username           | 
upstream_password           | 
ostree_upstream_sync_policy | 
ostree_upstream_sync_depth  | 
container_repository_name   | 
ignore_global_proxy         | f
deb_releases                | 
deb_components              | 
deb_architectures           | 
ssl_ca_cert_id              | 
ssl_client_cert_id          | 
ssl_client_key_id           | 
ignorable_content           | 
source_repo_checksum_type   | 

(the 1-rhelrepo-v1_0-15c2da4e-8d96-4d75-af1a-ff3bc7edb4ea shall be found in details of the repository in WebUI)

SBR
Product(s)
Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.