diff --git a/app/models/katello/repository.rb b/app/models/katello/repository.rb index 6888d9e0b5a..bc502d423f6 100644 --- a/app/models/katello/repository.rb +++ b/app/models/katello/repository.rb @@ -862,11 +862,20 @@ def self.search_by_content_label(_key, operator, value) def self.safe_render_container_name(repository, pattern = nil) if (pattern && !pattern.blank?) || (repository.environment && !repository.environment.registry_name_pattern.empty?) pattern ||= repository.environment.registry_name_pattern + environment = repository.environment + # For archived repositories, environment will be nil. In this case, get a + # valid env from the first non-archived repository. + environment ||= repository.content_view.repositories.first.environment allowed_methods = {} allowed_vars = {} - scope_variables = {repository: repository, organization: repository.organization, product: repository.product, - lifecycle_environment: repository.environment, content_view: repository.content_view_version.content_view, - content_view_version: repository.content_view_version} + scope_variables = { + repository: repository, + organization: repository.organization, + product: repository.product, + lifecycle_environment: environment, + content_view: repository.content_view_version.content_view, + content_view_version: repository.content_view_version + } box = Safemode::Box.new(repository, allowed_methods) erb = ERB.new(pattern) pattern = box.eval(erb.src, allowed_vars, scope_variables)