Topic.find_by crash


(Bohuslav Svancara) #1

Hello,

I am trying to migrate our proprietal forums data to Discourse.

I am able to convert users, categories and topics.

But trying to convert posts I ended with this SQL exception when Discourse performs the command:

topic = Topic.find_by(id: @opts[:topic_id])

in the PostCreator.setup_topic function.

(The Input argument is:
puts @opts[:topic_id]
{“topic_id”=>63, “post_number”=>1, “url”=>"/t/matrix-mania-dead-on-arrival/63/1"}
)

Can some good soul help me please?

Thank you,
Bob

Exception while creating post 27775416. Skipping.
PG::Error: ERROR:  missing FROM-clause entry for table "id"
LINE 1: ...opics"  WHERE ("topics"."deleted_at" IS NULL) AND "id"."topi...
                                                             ^
: SELECT  "topics".* FROM "topics"  WHERE ("topics"."deleted_at" IS NULL) AND "id"."topic_id" = 63 AND "id"."post_number" = 1 AND "id"."url" = '/t/matrix-mania-dead-on-arrival/63/1' LIMIT 1
/usr/local/rvm/gems/ruby-2.0.0-p0-turbo/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:822:in `exec'
/usr/local/rvm/gems/ruby-2.0.0-p0-turbo/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:822:in `block in exec_no_cache'
/usr/local/rvm/gems/ruby-2.0.0-p0-turbo/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract_adapter.rb:373:in `block in log'
/usr/local/rvm/gems/ruby-2.0.0-p0-turbo/gems/activesupport-4.1.6/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/usr/local/rvm/gems/ruby-2.0.0-p0-turbo/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract_adapter.rb:367:in `log'
/usr/local/rvm/gems/ruby-2.0.0-p0-turbo/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:822:in `exec_no_cache'
/usr/local/rvm/gems/ruby-2.0.0-p0-turbo/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql/database_statements.rb:137:in `exec_query'
/usr/local/rvm/gems/ruby-2.0.0-p0-turbo/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:954:in `select'
/usr/local/rvm/gems/ruby-2.0.0-p0-turbo/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/database_statements.rb:24:in `select_all'
/usr/local/rvm/gems/ruby-2.0.0-p0-turbo/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/query_cache.rb:70:in `select_all'
/usr/local/rvm/gems/ruby-2.0.0-p0-turbo/gems/activerecord-4.1.6/lib/active_record/querying.rb:39:in `find_by_sql'
/usr/local/rvm/gems/ruby-2.0.0-p0-turbo/gems/activerecord-4.1.6/lib/active_record/relation.rb:611:in `exec_queries'
/usr/local/rvm/gems/ruby-2.0.0-p0-turbo/gems/activerecord-4.1.6/lib/active_record/relation.rb:493:in `load'
/usr/local/rvm/gems/ruby-2.0.0-p0-turbo/gems/activerecord-4.1.6/lib/active_record/relation.rb:238:in `to_a'
/usr/local/rvm/gems/ruby-2.0.0-p0-turbo/gems/activerecord-4.1.6/lib/active_record/relation/finder_methods.rb:460:in `find_take'
/usr/local/rvm/gems/ruby-2.0.0-p0-turbo/gems/activerecord-4.1.6/lib/active_record/relation/finder_methods.rb:98:in `take'
/usr/local/rvm/gems/ruby-2.0.0-p0-turbo/gems/activerecord-4.1.6/lib/active_record/relation/finder_methods.rb:81:in `find_by'
/usr/local/rvm/gems/ruby-2.0.0-p0-turbo/gems/activerecord-4.1.6/lib/active_record/querying.rb:7:in `find_by'
/home/vagrant/vagrant/lib/post_creator.rb:197:in `setup_topic'
/home/vagrant/vagrant/lib/post_creator.rb:70:in `block in create'
/home/vagrant/vagrant/lib/distributed_mutex.rb:21:in `synchronize'
/home/vagrant/vagrant/lib/distributed_mutex.rb:5:in `synchronize'
/home/vagrant/vagrant/lib/post_creator.rb:137:in `block in transaction'
/usr/local/rvm/gems/ruby-2.0.0-p0-turbo/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in `block in transaction'
/usr/local/rvm/gems/ruby-2.0.0-p0-turbo/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/database_statements.rb:209:in `within_new_transaction'
/usr/local/rvm/gems/ruby-2.0.0-p0-turbo/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in `transaction'
/usr/local/rvm/gems/ruby-2.0.0-p0-turbo/gems/activerecord-4.1.6/lib/active_record/transactions.rb:208:in `transaction'
/home/vagrant/vagrant/lib/post_creator.rb:131:in `transaction'
/home/vagrant/vagrant/lib/post_creator.rb:69:in `create'
/home/vagrant/vagrant/script/import_scripts/base.rb:454:in `create_post'
/home/vagrant/vagrant/script/import_scripts/base.rb:401:in `block in create_posts'
/home/vagrant/vagrant/script/import_scripts/base.rb:381:in `each'
/home/vagrant/vagrant/script/import_scripts/base.rb:381:in `create_posts'
script/import_scripts/collective2.rb:79:in `execute'
/home/vagrant/vagrant/script/import_scripts/base.rb:71:in `perform'
script/import_scripts/collective2.rb:259:in `<main>'

(Bohuslav Svancara) #2

Ah - I see the problem: a wrong input argument.

Solved! :smile:


(Kane York) #3

When finding by id, you can just use Topic.find().


(Régis Hanol) #4