I started to learn Ruby on Rails and I am facing a problem with command logs.
I am starting my server with Command Prompt.
My Ruby version is: 2.7
My Rails version is: 7.0
I want to turn off or hide unnecessary logs.
Logs example:
Post Load (0.5ms) SELECT "posts".* FROM "posts" WHERE "posts"."author_id" = $1 ORDER BY "posts"."created_at" DESC LIMIT $2 [["author_id", 3], ["LIMIT", 3]]
Could not log "sql.active_record" event. Encoding::CompatibilityError: incompatible encoding regexp match (ASCII-8BIT regexp with UTF-8 string) [
"C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activesupport-7.0.4/lib/active_support/backtrace_cleaner.rb:96:in `sub'",
"C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activesupport-7.0.4/lib/active_support/backtrace_cleaner.rb:96:in `block in add_gem_filter'",
"C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activesupport-7.0.4/lib/active_support/backtrace_cleaner.rb:109:in `block (2 levels) in filter_backtrace'",
"C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-7.0.4/lib/active_record/log_subscriber.rb:144:in `each'",
"C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-7.0.4/lib/active_record/log_subscriber.rb:144:in `each'",
"C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-7.0.4/lib/active_record/log_subscriber.rb:144:in `each'",
"C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-7.0.4/lib/active_record/log_subscriber.rb:144:in `each'",
"C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-7.0.4/lib/active_record/log_subscriber.rb:144:in `first'",
"C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-7.0.4/lib/active_record/log_subscriber.rb:144:in `extract_query_source_location'",
"C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-7.0.4/lib/active_record/log_subscriber.rb:136:in `log_query_source'",
"C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-7.0.4/lib/active_record/log_subscriber.rb:131:in `debug'",
"C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-7.0.4/lib/active_record/log_subscriber.rb:71:in `sql'",
"C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activesupport-
I tried to find solution online, but I didn't find anything that will help me.
Related
We use Heroku review apps for QAing our PRs on Github. At some point a couple months ago we did some housekeeping and deleted a lot of old migration files and I think that is causing issues with the deploy on Heroku.
Here is my app.json file -
{
"name": "myapp",
"scripts": {
"postdeploy": "rake db:migrate db:seed db:fixtures:repopulate"
},
"env": {
"WEB_CONCURRENCY": "1",
"HEROKU_APP_NAME": {
"required": true
}
},
"formation": {
},
"addons": [
"heroku-redis",
{
"plan": "heroku-postgresql",
"options": {
"version": "9.6"
}
}
],
"buildpacks": [
]
}
Here is the results of running heroku releases:output -
Migrating to PopulateOldPasswordTable (20180305160642)
(1.3ms) BEGIN
== 20180305160642 PopulateOldPasswordTable: migrating =========================
User Load (2.5ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT $1 [["LIMIT", 1000]]
(1.2ms) ROLLBACK
(1.4ms) SELECT pg_advisory_unlock(5078732648953702200)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
PG::UndefinedTable: ERROR: relation "users" does not exist
LINE 1: SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIM...
^
: SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT $1
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/postgresql_adapter.rb:598:in `async_exec'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/postgresql_adapter.rb:598:in `block in exec_no_cache'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:589:in `block in log'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.2/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:583:in `log'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/postgresql_adapter.rb:598:in `exec_no_cache'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/postgresql_adapter.rb:587:in `execute_and_clear'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:103:in `exec_query'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:373:in `select'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:41:in `select_all'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/abstract/query_cache.rb:95:in `select_all'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/querying.rb:39:in `find_by_sql'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/relation.rb:702:in `exec_queries'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/relation.rb:583:in `load'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/relation.rb:260:in `records'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/relation/batches.rb:200:in `block in in_batches'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/relation/batches.rb:198:in `loop'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/relation/batches.rb:198:in `in_batches'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/relation/batches.rb:120:in `find_in_batches'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/relation/batches.rb:58:in `find_each'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/querying.rb:9:in `find_each'
/app/db/migrate/20180305160642_populate_old_password_table.rb:3:in `change'
It sounds like you deleted a migration that hadn't been run in all environments. You really don't want to do that.
The simplest way to recover, if the database doesn't contain anything of value, would be to destroy it and recreate it from scratch -- that'll use your schema.rb file, which should better match your other working environments.
If that isn't an option, consider bringing the old migration(s) back [via your git history], at least until you've finished running them everywhere.
I'm seeing this error thrown for multiple tables. Searching StackOverflow it seems most peoples problems are related to a specific column missing but in my case it's trying to select everything ie. using "*".
Anyone have any insight?
Mysql2::Error: Unknown column 'users.*' in 'field list'
UPDATE
From the rails log:
Mysql2::Error: Unknown column 'users.*' in 'field list': SELECT `users`.`*` FROM `users` WHERE `users`.`id` = 53 ORDER BY `users`.`id` ASC LIMIT 1
I figured out how to reproduce this locally or at least how I think it may be occurring:
2.1.2 :037 > client = Mysql2::Client.new(:host => "localhost", :username => "root", :password => "root", :database => "development")
=> #<Mysql2::Client:0x007ff45b72dd30 #read_timeout=nil, #query_options={:as=>:hash, :async=>false, :cast_booleans=>false, :symbolize_keys=>false, :database_timezone=>:local, :application_timezone=>nil, :cache_rows=>true, :connect_flags=>2147525125, :cast=>true, :host=>"localhost", :username=>"root", :password=>"root", :database=>"development"}>
2.1.2 :038 > result = client.query("SELECT `users`.`*` FROM `users` LIMIT 1")
Mysql2::Error: Unknown column 'users.*' in 'field list'
from (irb):40:in `query'
from (irb):40
from /Users/mark/.rvm/gems/ruby-2.1.2/gems/railties-4.1.7/lib/rails/commands/console.rb:90:in `start'
from /Users/mark/.rvm/gems/ruby-2.1.2/gems/railties-4.1.7/lib/rails/commands/console.rb:9:in `start'
from /Users/mark/.rvm/gems/ruby-2.1.2/gems/railties-4.1.7/lib/rails/commands/commands_tasks.rb:69:in `console'
from /Users/mark/.rvm/gems/ruby-2.1.2/gems/railties-4.1.7/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /Users/mark/.rvm/gems/ruby-2.1.2/gems/railties-4.1.7/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
The query:
SELECT `users`.`*` FROM `users` LIMIT 1
fails when the special all selector * is wrapped in quotes.
SELECT `users`.* FROM `users` LIMIT 1
works without issue. Perhaps that is a MySQL thing? Regardless, these queries are generated by ActiveRecord / ActiveModel so perhaps I've found a bug.
ActiveRecord 4.1.1 is generating some peculiar SQL on save that postgres is choking on:
SELECT "projects".* FROM "projects" WHERE ('uid') LIMIT 1
PG::InvalidTextRepresentation: ERROR: invalid input syntax for type boolean: "uid"
I'm pretty sure that the "boolean" being referred to here is actually the WHERE() syntax which is expecting a boolean expression as an argument.
uid is defined as the primary key on my model (see below)... but why is it just saying WHERE('uid') when it's doing select_all (see stacktrace)? (and why is it doing select_all on save?)
Rails Console
p = Project.new(name: "test", description: "test", workflow_id: 1)
=> #<Project name: "test", description: "test", user_id: nil, uid: nil, created_at: nil, updated_at: nil, workflow_id: 1, active: nil>
irb(main):031:0> p.save
(1.9ms) BEGIN
Project Load (5.5ms) SELECT "projects".* FROM "projects" WHERE ('uid') LIMIT 1
PG::InvalidTextRepresentation: ERROR: invalid input syntax for type boolean: "uid"
LINE 1: SELECT "projects".* FROM "projects" WHERE ('uid') LIMIT 1
^
: SELECT "projects".* FROM "projects" WHERE ('uid') LIMIT 1
(1.7ms) ROLLBACK
ActiveRecord::StatementInvalid: PG::InvalidTextRepresentation: ERROR: invalid input syntax for type boolean: "uid"
LINE 1: SELECT "projects".* FROM "projects" WHERE ('uid') LIMIT 1
^
: SELECT "projects".* FROM "projects" WHERE ('uid') LIMIT 1
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:815:in `async_exec'
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:815:in `block in exec_no_cache'
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:373:in `block in log'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:367:in `log'
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:815:in `exec_no_cache'
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:137:in `exec_query'
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:947:in `select'
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:31:in `select_all'
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/query_cache.rb:69:in `select_all'
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/querying.rb:39:in `find_by_sql'
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/relation.rb:603:in `exec_queries'
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/relation.rb:487:in `load'
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/relation.rb:231:in `to_a'
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/relation/finder_methods.rb:451:in `find_take'
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/relation/finder_methods.rb:98:in `take'
... 41 levels...
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `block in transaction'
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:219:in `within_new_transaction'
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `transaction'
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/transactions.rb:208:in `transaction'
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/transactions.rb:326:in `with_transaction_returning_status'
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/transactions.rb:268:in `block in save'
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/transactions.rb:283:in `rollback_active_record_state!'
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/transactions.rb:267:in `save'
from (irb):31
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/commands/console.rb:90:in `start'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/commands/console.rb:9:in `start'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:69:in `console'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/commands.rb:17:in `<top (required)>'
from /app/bin/rails:4:in `require'
from /app/bin/rails:4:in `<main>
Model
class Project < ActiveRecord::Base
self.primary_key = "uid"
end
ActiveRecord mixin for generating IDs
module ActiveRecordUIDExtension
extend ActiveSupport::Concern
def generate_uid
return unless self.class.column_names.include?("uid")
self.id = SecureRandom.random_number(36**10).to_s(36)
while !self.class.find_by(:uid, self.id).nil? do
self.id = SecureRandom.random_number(36**10).to_s(36)
end
end
end
ActiveRecord::Base.send(:include, ActiveRecordUIDExtension)
ActiveRecord::Base.send(:before_create, :generate_uid)
Gemfile.lock
activerecord (4.1.1)
activemodel (= 4.1.1)
activesupport (= 4.1.1)
arel (~> 5.0.0)
Your mixin doesn't make any sense. This part right here is causing the bad SQL:
self.class.find_by(:uid, self.id)
That's producing invalid SQL because you're telling it to. find_by has a flexible interface so it has to do some parsing to see how you're calling it. When you say:
find_by(a, b)
the argument parsing probably assumes that you're trying to use this form:
find_by('some_sql_snippet', placeholder_valid)
as in this example from the docs:
find_by("published_at < ?", 2.weeks.ago)
Then it will probably to_s the first argument and scan it for placeholders. When you say:
find_by(:uid, self.id)
you'll end up with :uid.to_s and self.id will be ignored because there aren't placeholders in that string. That would explain why you're seeing where ('uid') in the SQL.
Fix your mixin to make sense:
self.class.find_by(:uid => self.id)
or better, switch to exists? to avoid building a whole model instance just to see if there's a row in the database:
self.class.where(:uid => self.id).exists?
self.class.exists?(:uid => self.id)
I use find_by_sql and within a second it gives me back a response:
Report.find_by_sql("SELECT min(reports.time) FROM reports WHERE unit_id = '#{Unit.find(3007).id}' AND driver_id = '#{Driver.find(2).id}' AND time >= '#{beginning}' AND time <= '#{ending}'")
Unit Load (111.1ms) SELECT "units".* FROM "units" WHERE "units"."id" = $1 LIMIT 1 [["id", 3007]]
Driver Load (98.0ms) SELECT "drivers".* FROM "drivers" WHERE "drivers"."id" = $1 LIMIT 1 [["id", 2]]
Report Load (59.6ms) SELECT min(reports.time) FROM reports WHERE unit_id = '3007' AND driver_id = '2' AND time >= '2013-03-01 00:00:00 UTC
' AND time <= '2013-03-31 23:59:59 UTC'
=> [#<Report >]
Then I try to use a scope with activerecord relation methods to build the same query:
scope :start_driver_time, lambda { |unit, driver, start_time, end_time|
where("unit_id = ? AND
driver_id = ? AND
time >= ? AND
time <= ?",
unit.id, driver.id, start_time, end_time)
.order("time asc")
.minimum(:time)
}
1.9.3p0 :012 > Report.start_driver_time(Unit.find(3007), Driver.find(2), beginning, ending)
Unit Load (48.4ms) SELECT "units".* FROM "units" WHERE "units"."id" = $1 LIMIT 1 [["id", 3007]]
Driver Load (46.5ms) SELECT "drivers".* FROM "drivers" WHERE "drivers"."id" = $1 LIMIT 1 [["id", 2]]
(49.3ms) SELECT MIN("reports"."time") AS min_id FROM "reports" WHERE (unit_id = 3007 AND
driver_id = 2 AND
time >= '2013-03-01 00:00:00.000000' AND
time <= '2013-03-31 23:59:59.999999')
But after 45 minutes the query is still running.
When I press control + c this is the output:
^C Report Load (30484.0ms) SELECT "reports".* FROM "reports"
ActiveRecord::StatementInvalid: IRB::Abort: abort then interrupt!: SELECT "reports".* FROM "reports"
from /Users/johnmerlino/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/irb.rb:88:in `irb_abort'
from /Users/johnmerlino/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/irb.rb:257:in `signal_handle'
from /Users/johnmerlino/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/irb.rb:65:in `block in start'
from /Users/johnmerlino/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.5/lib/active_record/connection_adapters/postgresql_adapter.rb:1151:in `call'
from /Users/johnmerlino/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.5/lib/active_record/connection_adapters/postgresql_adapter.rb:1151:in `async_exec'
from /Users/johnmerlino/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.5/lib/active_record/connection_adapters/postgresql_adapter.rb:1151:in `exec_no_cache'
from /Users/johnmerlino/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.5/lib/active_record/connection_adapters/postgresql_adapter.rb:664:in `block in exec_query'
from /Users/johnmerlino/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
from /Users/johnmerlino/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.5/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
from /Users/johnmerlino/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
from /Users/johnmerlino/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.5/lib/active_record/connection_adapters/postgresql_adapter.rb:663:in `exec_query'
from /Users/johnmerlino/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.5/lib/active_record/connection_adapters/postgresql_adapter.rb:1246:in `select'
from /Users/johnmerlino/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:18:in `select_all'
from /Users/johnmerlino/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract/query_cache.rb:63:in `select_all'
from /Users/johnmerlino/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.5/lib/active_record/querying.rb:38:in `block in find_by_sql'
from /Users/johnmerlino/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.5/lib/active_record/explain.rb:40:in `logging_query_plan'
... 12 levels...
from /Users/johnmerlino/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/irb.rb:273:in `signal_status'
from /Users/johnmerlino/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/irb.rb:156:in `block in eval_input'
from /Users/johnmerlino/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/irb/ruby-lex.rb:243:in `block (2 levels) in each_top_level_statement'
from /Users/johnmerlino/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `loop'
from /Users/johnmerlino/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `block in each_top_level_statement'
from /Users/johnmerlino/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `catch'
from /Users/johnmerlino/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `each_top_level_statement'
from /Users/johnmerlino/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/irb.rb:155:in `eval_input'
from /Users/johnmerlino/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/irb.rb:70:in `block in start'
from /Users/johnmerlino/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/irb.rb:69:in `catch'
from /Users/johnmerlino/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/irb.rb:69:in `start'
from /Users/johnmerlino/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.5/lib/rails/commands/console.rb:47:in `start'
from /Users/johnmerlino/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.5/lib/rails/commands/console.rb:8:in `start'
from /Users/johnmerlino/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.5/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'Maybe IRB bug!
I think that scopes are usually meant to return a custom subset / join of the model, which may be causing the SELECT "reports".* FROM "reports" query after the others complete. Since it looks like you're on Rails 3 or higher, I'd replace the scope with a class method (the Rails Guide says "Using a class method is the preferred way to accept arguments for scopes.").
I am trying to test the sending on an email by DelayedJob using cucumber. The feature actually works in the browser (in both development and production environments) but I'm running into a weird SQlite3 exception when I try to test it.
The test log is at the bottom. As you can see, it fails with an SQLite3::SQLException just after inserting the email sending job into the queue.
According to Delayed::Job the reason for the failure is:
Delayed::DeserializationError
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/psych_ext.rb:108:in `rescue in visit_Psych_Nodes_Mapping_with_class'
Anyone got any idea what is happening here?
I found a related question but the problem there doesn't appear to be constrained to the test environment. Thus I don't think the solution will be the same.
SQLite3 Error - cannot rollback - no transaction is active
Here's the full test trace:
SQL (82.7ms) INSERT INTO "delayed_jobs" ("attempts", "created_at", "failed_at", "handler", "last_error", "locked_at", "locked_by", "priority", "queue", "run_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [["attempts", 0], ["created_at", Tue, 08 May 2012 12:14:15 UTC +00:00], ["failed_at", nil], ["handler", "--- !ruby/object:Delayed::PerformableMailer\nobject: !ruby/class 'InvitationMailer'\nmethod_name: :invite\nargs:\n- !ruby/ActiveRecord:Invitation\n attributes:\n id: 1\n sender_id: 1\n search_id: 1\n token: 4cba1a8a36de826493b1d8a8cc21091e2fb393e1\n sent_at: \n recipient_email: peter#example.com\n created_at: 2012-05-08 12:14:15.702071000 Z\n updated_at: 2012-05-08 12:14:15.702071000 Z\n recipient_id: \n accepted: \n"], ["last_error", nil], ["locked_at", nil], ["locked_by", nil], ["priority", 0], ["queue", nil], ["run_at", Tue, 08 May 2012 12:14:15 UTC +00:00], ["updated_at", Tue, 08 May 2012 12:14:15 UTC +00:00]]
(0.9ms) commit transaction
SQLite3::SQLException: cannot commit - no transaction is active: commit transaction
(0.5ms) rollback transaction
SQLite3::SQLException: cannot rollback - no transaction is active: rollback transaction
Completed 500 Internal Server Error in 126ms
SQL (1.9ms) UPDATE "delayed_jobs" SET locked_at = '2012-05-08 12:14:16.993126', locked_by = 'host:dtmbp.local pid:14059' WHERE (id = 3 and (locked_at is null or locked_at < '2012-05-08 08:14:16.993126') and (run_at <= '2012-05-08 12:14:16.993126'))
Invitation Load (0.2ms) SELECT "invitations".* FROM "invitations" WHERE "invitations"."id" = ? LIMIT 1 [["id", 1]]
Invitation Load (0.1ms) SELECT "invitations".* FROM "invitations" WHERE "invitations"."id" = ? LIMIT 1 [["id", 1]]
Invitation Load (0.1ms) SELECT "invitations".* FROM "invitations" WHERE "invitations"."id" = ? LIMIT 1 [["id", 1]]
Invitation Load (0.1ms) SELECT "invitations".* FROM "invitations" WHERE "invitations"."id" = ? LIMIT 1 [["id", 1]]
Invitation Load (0.1ms) SELECT "invitations".* FROM "invitations" WHERE "invitations"."id" = ? LIMIT 1 [["id", 1]]
(0.1ms) begin transaction
(0.5ms) UPDATE "delayed_jobs" SET "locked_at" = '2012-05-08 12:14:16.993126', "locked_by" = 'host:dtmbp.local pid:14059', "last_error" = '{Delayed::DeserializationError
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/psych_ext.rb:108:in `rescue in visit_Psych_Nodes_Mapping_with_class''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/psych_ext.rb:101:in `visit_Psych_Nodes_Mapping_with_class''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/visitor.rb:15:in `visit''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/visitor.rb:5:in `accept''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:20:in `accept''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:134:in `block in visit_Psych_Nodes_Sequence''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:134:in `each''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:134:in `visit_Psych_Nodes_Sequence''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/visitor.rb:15:in `visit''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/visitor.rb:5:in `accept''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:20:in `accept''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:276:in `block in revive''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:276:in `map''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:276:in `revive''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:219:in `visit_Psych_Nodes_Mapping''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/psych_ext.rb:119:in `visit_Psych_Nodes_Mapping_with_class''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/visitor.rb:15:in `visit''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/visitor.rb:5:in `accept''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:20:in `accept''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:231:in `visit_Psych_Nodes_Document''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/visitor.rb:15:in `visit''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/visitor.rb:5:in `accept''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:20:in `accept''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/nodes/node.rb:35:in `to_ruby''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych.rb:128:in `load''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/backend/base.rb:84:in `payload_object''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/backend/base.rb:94:in `block in invoke_job''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:60:in `call''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:60:in `block in initialize''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:65:in `call''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:65:in `execute''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:38:in `run_callbacks''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/backend/base.rb:91:in `invoke_job''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/worker.rb:178:in `block (2 levels) in run''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/timeout.rb:68:in `timeout''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/worker.rb:178:in `block in run''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/benchmark.rb:295:in `realtime''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/worker.rb:177:in `run''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/worker.rb:234:in `block in reserve_and_run_one_job''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:60:in `call''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:60:in `block in initialize''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:65:in `call''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:65:in `execute''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:38:in `run_callbacks''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/worker.rb:234:in `reserve_and_run_one_job''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/worker.rb:162:in `block in work_off''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/worker.rb:161:in `times''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/worker.rb:161:in `work_off''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/worker.rb:133:in `block (4 levels) in start''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/benchmark.rb:295:in `realtime''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/worker.rb:132:in `block (3 levels) in start''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:60:in `call''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:60:in `block in initialize''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:65:in `call''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:65:in `execute''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:38:in `run_callbacks''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/worker.rb:129:in `block (2 levels) in start''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/worker.rb:128:in `loop''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/worker.rb:128:in `block in start''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/plugins/clear_locks.rb:7:in `call''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/plugins/clear_locks.rb:7:in `block (2 levels) in <class:ClearLocks>''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:78:in `call''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:78:in `block (2 levels) in add''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:60:in `call''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:60:in `block in initialize''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:78:in `call''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:78:in `block in add''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:65:in `call''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:65:in `execute''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:38:in `run_callbacks''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/worker.rb:127:in `start''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/tasks.rb:9:in `block (2 levels) in <top (required)>''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/bin/rake:19:in `load''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/bin/rake:19:in `<main>''', "failed_at" = '2012-05-08 12:14:17.131476', "updated_at" = '2012-05-08 12:14:17.132975' WHERE "delayed_jobs"."id" = 3
(1.5ms) commit transaction
I just had this error and realized that the AR object in question had simply already been deleted. Maybe that's your situation too?
Related link: psych_ext.rb#L101 breaks restoring of deleted serialized objects