{"action":"created","issue":{"url":"https://api.github.com/repos/rails/rails/issues/19405","labels_url":"https://api.github.com/repos/rails/rails/issues/19405/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/19405/comments","events_url":"https://api.github.com/repos/rails/rails/issues/19405/events","html_url":"https://github.com/rails/rails/issues/19405","id":62951207,"number":19405,"title":"Defining :run callbacks breaks whole callbacks infrastructure","user":{"login":"katafrakt","id":119904,"avatar_url":"https://avatars.githubusercontent.com/u/119904?v=3","gravatar_id":"","url":"https://api.github.com/users/katafrakt","html_url":"https://github.com/katafrakt","followers_url":"https://api.github.com/users/katafrakt/followers","following_url":"https://api.github.com/users/katafrakt/following{/other_user}","gists_url":"https://api.github.com/users/katafrakt/gists{/gist_id}","starred_url":"https://api.github.com/users/katafrakt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/katafrakt/subscriptions","organizations_url":"https://api.github.com/users/katafrakt/orgs","repos_url":"https://api.github.com/users/katafrakt/repos","events_url":"https://api.github.com/users/katafrakt/events{/privacy}","received_events_url":"https://api.github.com/users/katafrakt/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-03-19T10:42:41Z","updated_at":"2015-04-07T08:33:19Z","closed_at":"2015-04-06T21:58:37Z","body":"When you define `:run` callbacks, anything that calls any callbacks breaks with quite vague error message:\r\n\r\n```\r\n/home/katafrakt/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0/lib/active_support/core_ext/class/attribute.rb:106:in `block (2 levels) in class_attribute': wrong number of arguments (1 for 0) (ArgumentError)\r\n\tfrom /home/katafrakt/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:734:in `_run_run_callbacks'\r\n\tfrom /home/katafrakt/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:81:in `run_callbacks'\r\n```\r\n\r\nThis behaviour can be easily reproduced with following script:\r\n\r\n```ruby\r\ngem 'activesupport', '4.2.0'\r\nrequire 'active_support/all'\r\n\r\nclass Machine\r\n\tinclude ActiveSupport::Callbacks\r\n\tdefine_callbacks :run\r\n\r\n\tdef start\r\n\t\trun_callbacks(:run) do\r\n\t\t\tputs \"running\"\r\n\t\tend\r\n\tend\r\nend\r\n\r\nm = Machine.new\r\nm.start\r\n```\r\n\r\nThis is caused by how `define callbacks` method works. In this case it creates class attribute `_run_callbacks` and defines method `_run_run_callbacks` that calls internal `_run_callbacks` method, which is now overriden by class attribute. In fact, running any callbacks (not only `run`) will result in error message above.\r\n\r\n```ruby\r\n      def define_callbacks(*names)\r\n        options = names.extract_options!\r\n\r\n        names.each do |name|\r\n          class_attribute \"_#{name}_callbacks\"\r\n          set_callbacks name, CallbackChain.new(name, options)\r\n\r\n          module_eval <<-RUBY, __FILE__, __LINE__ + 1\r\n            def _run_#{name}_callbacks(&block)\r\n              _run_callbacks(_#{name}_callbacks, &block)\r\n            end\r\n          RUBY\r\n        end\r\n      end\r\n```\r\n\r\nIt works with version 3.2.15, I'm not sure about intermediate versions. Master is also affected.\r\n\r\n**Proposed solution**\r\n\r\nRaise error with clear message when user tries to define `:run` callback. I can PR this unless someone comes up with better idea."},"comment":{"url":"https://api.github.com/repos/rails/rails/issues/comments/90461972","html_url":"https://github.com/rails/rails/issues/19405#issuecomment-90461972","issue_url":"https://api.github.com/repos/rails/rails/issues/19405","id":90461972,"user":{"login":"katafrakt","id":119904,"avatar_url":"https://avatars.githubusercontent.com/u/119904?v=3","gravatar_id":"","url":"https://api.github.com/users/katafrakt","html_url":"https://github.com/katafrakt","followers_url":"https://api.github.com/users/katafrakt/followers","following_url":"https://api.github.com/users/katafrakt/following{/other_user}","gists_url":"https://api.github.com/users/katafrakt/gists{/gist_id}","starred_url":"https://api.github.com/users/katafrakt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/katafrakt/subscriptions","organizations_url":"https://api.github.com/users/katafrakt/orgs","repos_url":"https://api.github.com/users/katafrakt/repos","events_url":"https://api.github.com/users/katafrakt/events{/privacy}","received_events_url":"https://api.github.com/users/katafrakt/received_events","type":"User","site_admin":false},"created_at":"2015-04-07T08:33:19Z","updated_at":"2015-04-07T08:33:19Z","body":"I guess the fix won't end up in 4.2 line?"}}