{"action":"closed","issue":{"url":"https://api.github.com/repos/collectiveidea/delayed_job/issues/805","labels_url":"https://api.github.com/repos/collectiveidea/delayed_job/issues/805/labels{/name}","comments_url":"https://api.github.com/repos/collectiveidea/delayed_job/issues/805/comments","events_url":"https://api.github.com/repos/collectiveidea/delayed_job/issues/805/events","html_url":"https://github.com/collectiveidea/delayed_job/issues/805","id":71198356,"number":805,"title":"Calling delay on an ActiveRecord object not in scope crashes","user":{"login":"hult","id":374824,"avatar_url":"https://avatars.githubusercontent.com/u/374824?v=3","gravatar_id":"","url":"https://api.github.com/users/hult","html_url":"https://github.com/hult","followers_url":"https://api.github.com/users/hult/followers","following_url":"https://api.github.com/users/hult/following{/other_user}","gists_url":"https://api.github.com/users/hult/gists{/gist_id}","starred_url":"https://api.github.com/users/hult/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hult/subscriptions","organizations_url":"https://api.github.com/users/hult/orgs","repos_url":"https://api.github.com/users/hult/repos","events_url":"https://api.github.com/users/hult/events{/privacy}","received_events_url":"https://api.github.com/users/hult/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-04-27T07:10:20Z","updated_at":"2015-04-27T14:17:34Z","closed_at":"2015-04-27T14:17:34Z","body":"I have an active record model class with a default scope\r\n\r\n    class MyModel < ActiveRecord::Base\r\n      default_scope { where deleted_at: nil }\r\n      def do_someting; puts deleted_at; end\r\n    end\r\n\r\nIf I delay a job on an instance of this model not in scope\r\n\r\n    MyModel.create!(deleted_at: Time.now).delay.do_something\r\n\r\nthen the entire worker process crashes\r\n\r\n    ActiveRecord::RecordNotFound: Couldn't find MyModel with 'id'=1 [WHERE \"my_models\".\"deleted_at\" IS NULL]\r\n\r\n```\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/gems/activerecord-4.1.6/lib/active_record/relation/finder_methods.rb:320:in `raise_record_not_found_exception!'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/gems/activerecord-4.1.6/lib/active_record/relation/finder_methods.rb:429:in `find_one'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/gems/activerecord-4.1.6/lib/active_record/relation/finder_methods.rb:413:in `find_with_ids'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/gems/activerecord-4.1.6/lib/active_record/relation/finder_methods.rb:68:in `find'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/gems/activerecord-4.1.6/lib/active_record/querying.rb:3:in `find'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/psych_ext.rb:40:in `visit_Psych_Nodes_Mapping'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/psych_ext.rb:35:in `visit_Psych_Nodes_Mapping'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/psych_ext.rb:17:in `load_dj'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/backend/base.rb:91:in `payload_object'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/backend/base.rb:138:in `max_run_time'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/worker.rb:284:in `max_run_time'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/worker.rb:223:in `block in run'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/worker.rb:222:in `run'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/worker.rb:299:in `block in reserve_and_run_one_job'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/lifecycle.rb:61:in `call'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/lifecycle.rb:61:in `block in initialize'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/lifecycle.rb:66:in `call'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/lifecycle.rb:66:in `execute'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/lifecycle.rb:40:in `run_callbacks'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/worker.rb:299:in `reserve_and_run_one_job'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/worker.rb:206:in `block in work_off'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/worker.rb:205:in `times'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/worker.rb:205:in `work_off'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/worker.rb:169:in `block (4 levels) in start'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/worker.rb:168:in `block (3 levels) in start'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/lifecycle.rb:61:in `call'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/lifecycle.rb:61:in `block in initialize'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/lifecycle.rb:66:in `call'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/lifecycle.rb:66:in `execute'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/lifecycle.rb:40:in `run_callbacks'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/worker.rb:167:in `block (2 levels) in start'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/worker.rb:166:in `loop'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/worker.rb:166:in `block in start'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/plugins/clear_locks.rb:7:in `call'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/plugins/clear_locks.rb:7:in `block (2 levels) in <class:ClearLocks>'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/lifecycle.rb:79:in `call'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/lifecycle.rb:79:in `block (2 levels) in add'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/lifecycle.rb:61:in `call'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/lifecycle.rb:61:in `block in initialize'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/lifecycle.rb:79:in `call'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/lifecycle.rb:79:in `block in add'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/lifecycle.rb:66:in `call'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/lifecycle.rb:66:in `execute'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/lifecycle.rb:40:in `run_callbacks'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/worker.rb:165:in `start'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bundler/gems/delayed_job-ce8869342918/lib/delayed/tasks.rb:9:in `block (2 levels) in <top (required)>'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bin/ruby_executable_hooks:15:in `eval'\r\n08:55:17 worker.1 | /Users/magnus/.rvm/gems/ruby-2.1.3/bin/ruby_executable_hooks:15:in `<main>'\r\n08:55:17 worker.1 | Tasks: TOP => jobs:work\r\n08:55:17 worker.1 | (See full trace by running task with --trace)\r\n08:55:17 worker.1 | exited with code 1\r\n08:55:17 system   | sending SIGTERM to all processes\r\n```"}}