Project

General

Profile

Bug #1707

db:migrate fail on in bookmark.rb with ruby1.9

Added by Ky Zh about 7 years ago. Updated about 7 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
DB migrations
Target version:
Difficulty:
trivial
Triaged:
No
Bugzilla link:
Pull request:
Team Backlog:
Fixed in Releases:
Found in Releases:

Description

I edited app/models/bookmark.rb, and removed the condition "unless"
It seems to work. I still think that this is fixing the symptom not the problem.

[foreman@ms1 foreman]$ diff -u /tmp/bookmark.rb.old /tmp/bookmark.rb
--- /tmp/bookmark.rb    2012-06-25 21:10:59.740785531 +0100
+++ /tmp/bookmark.rb.old    2012-06-25 21:10:43.277432124 +0100
@@ -2,7 +2,7 @@
   belongs_to :owner, :polymorphic => true
   attr_accessible :name, :controller, :query, :public

-  validates_uniqueness_of :name, :unless => Proc.new{|b| Bookmark.my_bookmarks(:conditions => {:name => b.name}).empty?}
+  validates_uniqueness_of :name
   validates_presence_of :name
   validates_format_of :controller, :with => /\A(\S+)\Z/, :message => "can't be blank or contain white spaces." 
   validates_presence_of :query

I used "allow_blank: true" with success (https://github.com/rails/rails/issues/5853)
But as i'm not sure it's the intended, best practice, i leave it for a more knowledgeable person to tell.

I installed from git (59be369d36) today.
The db is sqlite from scratch.
I also found 2 pastie with the same problem [1] [2]

Here is thre trace with ":unless"


[foreman@ms1 foreman]$ RAILS_ENV=production  rake db:migrate --trace
Libvirt binding are missing - hypervisor management is disabled
/opt/foreman/.gem/ruby/1.9.1/gems/ruby_parser-2.3.1/lib/ruby_parser_extras.rb:10: warning: already initialized constant ENC_NONE
/opt/foreman/.gem/ruby/1.9.1/gems/ruby_parser-2.3.1/lib/ruby_parser_extras.rb:11: warning: already initialized constant ENC_EUC
/opt/foreman/.gem/ruby/1.9.1/gems/ruby_parser-2.3.1/lib/ruby_parser_extras.rb:12: warning: already initialized constant ENC_SJIS
/opt/foreman/.gem/ruby/1.9.1/gems/ruby_parser-2.3.1/lib/ruby_parser_extras.rb:13: warning: already initialized constant ENC_UTF8
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
==  AddTableBookmarks: migrating ==============================================
-- create_table(:bookmarks, {:force=>true})
   -> 0.0030s
-- add_index(:bookmarks, :name)
   -> 0.0006s
-- add_index(:bookmarks, :controller)
   -> 0.0008s
-- add_index(:bookmarks, [:owner_id, :owner_type])
   -> 0.0008s
rake aborted!
An error has occurred, this and all later migrations canceled:

wrong number of arguments (1 for 0)
/opt/foreman/foreman/app/models/bookmark.rb:13:in `block in <class:Bookmark>'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/named_scope.rb:107:in `call'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/named_scope.rb:107:in `block in scope'
/opt/foreman/foreman/app/models/bookmark.rb:5:in `block in <class:Bookmark>'
/opt/foreman/.gem/ruby/1.9.1/gems/activesupport-3.0.15/lib/active_support/callbacks.rb:414:in `_run_validate_callbacks'
/opt/foreman/.gem/ruby/1.9.1/gems/activemodel-3.0.15/lib/active_model/validations.rb:212:in `run_validations!'
/opt/foreman/.gem/ruby/1.9.1/gems/activemodel-3.0.15/lib/active_model/validations/callbacks.rb:67:in `block in run_validations!'
/opt/foreman/.gem/ruby/1.9.1/gems/activesupport-3.0.15/lib/active_support/callbacks.rb:419:in `_run_validation_callbacks'
/opt/foreman/.gem/ruby/1.9.1/gems/activemodel-3.0.15/lib/active_model/validations/callbacks.rb:67:in `run_validations!'
/opt/foreman/.gem/ruby/1.9.1/gems/activemodel-3.0.15/lib/active_model/validations.rb:179:in `valid?'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/validations.rb:55:in `valid?'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/validations.rb:75:in `perform_validations'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/validations.rb:43:in `save'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/attribute_methods/dirty.rb:21:in `save'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/transactions.rb:240:in `block (2 levels) in save'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/transactions.rb:292:in `block in with_transaction_returning_status'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/transactions.rb:207:in `transaction'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/transactions.rb:290:in `with_transaction_returning_status'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/transactions.rb:240:in `block in save'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/transactions.rb:251:in `rollback_active_record_state!'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/transactions.rb:239:in `save'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/relation/finder_methods.rb:273:in `find_or_instantiator_by_attributes'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/base.rb:995:in `method_missing'
/opt/foreman/foreman/db/migrate/20110417102947_add_table_bookmarks.rb:17:in `up'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/migration.rb:314:in `block in migrate'
/usr/lib/ruby/1.9.1/benchmark.rb:280:in `measure'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/migration.rb:314:in `migrate'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/migration.rb:397:in `migrate'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/migration.rb:539:in `block (2 levels) in migrate'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/migration.rb:613:in `call'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/migration.rb:613:in `block in ddl_transaction'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/transactions.rb:207:in `transaction'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/migration.rb:613:in `ddl_transaction'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/migration.rb:538:in `block in migrate'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/migration.rb:525:in `each'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/migration.rb:525:in `migrate'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/migration.rb:435:in `up'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/migration.rb:417:in `migrate'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/railties/databases.rake:151:in `block (2 levels) in <top (required)>'
/usr/lib/ruby/1.9.1/rake/task.rb:205:in `call'
/usr/lib/ruby/1.9.1/rake/task.rb:205:in `block in execute'
/usr/lib/ruby/1.9.1/rake/task.rb:200:in `each'
/usr/lib/ruby/1.9.1/rake/task.rb:200:in `execute'
/usr/lib/ruby/1.9.1/rake/task.rb:158:in `block in invoke_with_call_chain'
/usr/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/usr/lib/ruby/1.9.1/rake/task.rb:151:in `invoke_with_call_chain'
/usr/lib/ruby/1.9.1/rake/task.rb:144:in `invoke'
/usr/lib/ruby/1.9.1/rake/application.rb:116:in `invoke_task'
/usr/lib/ruby/1.9.1/rake/application.rb:94:in `block (2 levels) in top_level'
/usr/lib/ruby/1.9.1/rake/application.rb:94:in `each'
/usr/lib/ruby/1.9.1/rake/application.rb:94:in `block in top_level'
/usr/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling'
/usr/lib/ruby/1.9.1/rake/application.rb:88:in `top_level'
/usr/lib/ruby/1.9.1/rake/application.rb:66:in `block in run'
/usr/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling'
/usr/lib/ruby/1.9.1/rake/application.rb:63:in `run'
/usr/bin/rake:32:in `<main>'
Tasks: TOP => db:migrate

It work without the "unless" and a clean db:
I used bundler, and he gems are in $HOME (gem: --user-install in the gemrc)

[foreman@ms1 foreman]$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]

[foreman@ms1 foreman]$ gem list --local
*** LOCAL GEMS ***
abstract (1.0.0)
actionmailer (3.0.15)
actionpack (3.0.15)
activemodel (3.0.15)
activerecord (3.0.15)
activeresource (3.0.15)
activesupport (3.0.15)
ancestry (1.2.5)
archive-tar-minitar (0.5.2)
arel (2.0.10)
audited (3.0.0.rc1)
audited-activerecord (3.0.0.rc1)
awesome_print (1.0.2)
bigdecimal (1.1.0)
builder (2.1.2)
bundle (0.0.1)
bundler (1.1.4)
columnize (0.3.6)
erubis (2.6.6)
excon (0.14.1)
formatador (0.2.3)
hirb (0.6.2)
hirb-unicode (0.0.5)
i18n (0.5.0)
io-console (0.3)
jquery-rails (1.0.19)
json (1.7.3, 1.5.4)
linecache19 (0.5.12)
mail (2.2.19)
metaclass (0.0.1)
mime-types (1.19)
minitest (2.5.1)
mocha (0.11.4)
multi_json (1.3.6)
mysql (2.8.1)
mysql2 (0.2.18)
net-ldap (0.3.1)
net-scp (1.0.4)
net-ssh (2.5.2)
nokogiri (1.5.5)
pg (0.14.0)
polyglot (0.3.3)
rack (1.2.5)
rack-mount (0.6.14)
rack-test (0.5.7)
rails (3.0.15)
railties (3.0.15)
rake (0.9.2.2)
rbovirt (0.0.12)
rbvmomi (1.5.1)
rdoc (3.12, 3.9.4)
rest-client (1.6.7)
rr (1.0.4)
ruby-debug-base19 (0.11.25)
ruby-debug19 (0.11.6)
ruby-hmac (0.4.0)
ruby2ruby (1.3.1)
ruby_core_source (0.1.5)
ruby_parser (2.3.1)
rubygems-update (1.8.24)
safemode (1.0.1)
scoped_search (2.3.7)
sexp_processor (3.2.0)
shoulda (3.0.1)
shoulda-context (1.0.0)
shoulda-matchers (1.0.0)
sqlite3 (1.3.6)
thor (0.14.6)
treetop (1.4.10)
trollop (1.16.2)
tzinfo (0.3.33)
unicode-display_width (0.1.1)
uuidtools (2.1.2)
will_paginate (3.0.3)
wirb (0.4.2)

[1] http://pastie.org/pastes/3540977
[2] http://www.pastie.org/pastes/3810833


Related issues

Has duplicate Foreman - Bug #1706: db:migrate fail on in bookmark.rbDuplicate2012-06-25

Associated revisions

Revision 88e855b2 (diff)
Added by Ohad Levy about 7 years ago

fixes #1707 - db:migrate fail on in bookmark.rb with ruby1.9

History

#1 Updated by Ky Zh about 7 years ago

So far i think that the admin account is not created properlly for one reason or another.
Then bookmark cannot be created and fail on User.current = User.find_by_login("admin") in the migration.

When i start the application i have a error pop up that would corroborate the above :
"Unable to find internal system admin account - Recreating... "

It doesn't seems to be a lot of commit recently done to the account creation.
I will see if i can bisect the problem tomorrow .

#2 Updated by Ohad Levy about 7 years ago

  • Subject changed from db:migrate fail on in bookmark.rb to db:migrate fail on in bookmark.rb with ruby1.9
  • Assignee set to Ohad Levy
  • Target version set to 1.0

#3 Updated by Ky Zh about 7 years ago

I pulled 88e855b239, works for me now, thanks

#4 Updated by Ohad Levy about 7 years ago

  • Status changed from New to Closed
  • % Done changed from 0 to 100

Also available in: Atom PDF