Project

General

Profile

Actions

Bug #16023

closed

Upgrade fails during migration.

Added by Ranjan Kumar over 7 years ago. Updated over 7 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Category:
DB migrations
Target version:
-
Difficulty:
Triaged:
Fixed in Releases:
Found in Releases:

Description

Upgrade Step: migrate_foreman...
rake aborted!

NoMethodError: undefined method `value' for nil:NilClass
/usr/share/foreman/lib/tasks/config.rake:103:in `block in run_key_values'
/usr/share/foreman/lib/tasks/config.rake:100:in `each'
/usr/share/foreman/lib/tasks/config.rake:100:in `run_key_values'
/usr/share/foreman/lib/tasks/config.rake:77:in `run'
/usr/share/foreman/lib/tasks/config.rake:150:in `block in <top (required)>'
Tasks: TOP => config
(See full trace by running task with --trace)
API controllers newer than Apipie cache! Run apipie:cache rake task to regenerate cache.

rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

wrong number of arguments (2 for 1)/usr/share/foreman/app/models/setting.rb:169:in `create'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/relation.rb:132:in `block in create'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/relation.rb:285:in `scoping'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/relation.rb:132:in `create'
/opt/theforeman/tfm/root/usr/share/gems/gems/protected_attributes-1.1.3/lib/active_record/mass_assignment_security/relation.rb:35:in `first_or_create'
/usr/share/foreman/app/models/setting.rb:82:in `[]='
/usr/share/foreman/db/migrate/20150114141626_actually_rename_smart_proxy_auth_related_settings.rb:5:in `block in up'
/usr/share/foreman/db/migrate/20150114141626_actually_rename_smart_proxy_auth_related_settings.rb:3:in `each'
/usr/share/foreman/db/migrate/20150114141626_actually_rename_smart_proxy_auth_related_settings.rb:3:in `up'


Files

console.txt console.txt 13.4 KB Upgrade log Ranjan Kumar, 08/11/2016 07:15 AM
output.txt output.txt 138 KB setting table records Ranjan Kumar, 08/11/2016 07:15 AM
Actions #1

Updated by Ranjan Kumar over 7 years ago

After making below changes it works. Any thought this?

+++ app/models/setting.rb
@@ -85,7 +85,7 @@ class Setting < ActiveRecord::Base

   def self.[]=(name, value)
     name   = name.to_s
-    record = where(:name => name).first_or_create
+    record = where(:name => name).first
     record.value = value
     record.save!
   end
diff --git a/db/migrate/20150114141626_actually_rename_smart_proxy_auth_related_settings.rb b/db/migrate/20150114141626_actually_rename_smart_proxy_auth_related_settings.rb
index c590483..c152166 100644
+++ b/db/migrate/20150114141626_actually_rename_smart_proxy_auth_related_settings.rb
@@ -2,8 +2,7 @@ class ActuallyRenameSmartProxyAuthRelatedSettings < ActiveRecord::Migration
   def up
     %w(restrict_registered require_ssl).each do |setting|
       if (old = Setting.find_by_name("#{setting}_puppetmasters"))
-        Setting["#{setting}_smart_proxies"] = old.value
-        old.delete
+        old.update_column(:name, "#{setting}_smart_proxies")
       end
     end
   end

Actions #2

Updated by Marek Hulán over 7 years ago

  • Description updated (diff)
  • Category set to DB migrations
Actions #3

Updated by Ranjan Kumar over 7 years ago

After making below changes it works. Any thought this?

app/models/setting.rb
class Setting < ActiveRecord::Base

def self.[]=(name, value)
name = name.to_s
- record = where(:name => name).first_or_create
+ record = where(:name => name).first
record.value = value
record.save!
end
diff --git a/db/migrate/20150114141626_actually_rename_smart_proxy_auth_related_settings.rb b/db/migrate/20150114141626_actually_rename_smart_proxy_auth_related_settings.rb

db/migrate/20150114141626_actually_rename_smart_proxy_auth_related_settings.rb
class ActuallyRenameSmartProxyAuthRelatedSettings < ActiveRecord::Migration
def up
%w(restrict_registered require_ssl).each do |setting|
if (old = Setting.find_by_name("#{setting}_puppetmasters"))
- Setting["#{setting}_smart_proxies"] = old.value
- old.delete
old.update_column(:name, "#{setting}_smart_proxies")
end
end
end

Actions #4

Updated by Dominic Cleal over 7 years ago

NoMethodError: undefined method `value' for nil:NilClass
/usr/share/foreman/lib/tasks/config.rake:103:in `block in run_key_values'

This looks like it's been fixed in 1.12.0 via #14843.

wrong number of arguments (2 for 1)/
usr/share/foreman/app/models/setting.rb:169:in `create'
/opt/theforeman/tfm/root/usr/share/gems/gems/protected_attributes-1.1.3/lib/active_record/mass_assignment_security/relation.rb:35:in `first_or_create'

This method signature change should be obsolete in develop via #3917. It's unclear from the bits of output you pasted why the setting hasn't been initialised.

Updated by Ranjan Kumar over 7 years ago

Attached upgrade log and records of settings table. Since satellite 6.2 is using foreman-1.11.0.49-1, pr #14843 is not included.

Actions #6

Updated by Marek Hulán over 7 years ago

  • Status changed from New to Need more information

Ranjan, why not just backporting the PR from #14843? It seems small enough.

Actions #7

Updated by Ranjan Kumar over 7 years ago

Not reproducible, close this ticket.

Actions #8

Updated by Dominic Cleal over 7 years ago

  • Status changed from Need more information to Rejected
Actions

Also available in: Atom PDF