{"action":"closed","issue":{"url":"https://api.github.com/repos/rails/rails/issues/25732","repository_url":"https://api.github.com/repos/rails/rails","labels_url":"https://api.github.com/repos/rails/rails/issues/25732/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/25732/comments","events_url":"https://api.github.com/repos/rails/rails/issues/25732/events","html_url":"https://github.com/rails/rails/issues/25732","id":164250591,"number":25732,"title":"ERROR:  bind message supplies 0 parameters, but prepared statement \"\" requires 1","user":{"login":"Tietew","id":51289,"avatar_url":"https://avatars.githubusercontent.com/u/51289?v=3","gravatar_id":"","url":"https://api.github.com/users/Tietew","html_url":"https://github.com/Tietew","followers_url":"https://api.github.com/users/Tietew/followers","following_url":"https://api.github.com/users/Tietew/following{/other_user}","gists_url":"https://api.github.com/users/Tietew/gists{/gist_id}","starred_url":"https://api.github.com/users/Tietew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tietew/subscriptions","organizations_url":"https://api.github.com/users/Tietew/orgs","repos_url":"https://api.github.com/users/Tietew/repos","events_url":"https://api.github.com/users/Tietew/events{/privacy}","received_events_url":"https://api.github.com/users/Tietew/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rails/rails/labels/activerecord","name":"activerecord","color":"0b02e1"},{"url":"https://api.github.com/repos/rails/rails/labels/attached%20PR","name":"attached PR","color":"006b75"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-07-07T07:57:21Z","updated_at":"2016-07-20T15:56:57Z","closed_at":"2016-07-20T15:56:57Z","body":"### Steps to reproduce\r\n\r\n``` ruby\r\nrequire 'bundler/inline'\r\n\r\ngemfile(true) do\r\n  source 'https://rubygems.org'\r\n  gem 'activerecord', github: 'rails/rails'\r\n  gem 'pg'\r\nend\r\n\r\nrequire 'active_record'\r\nrequire 'minitest/autorun'\r\nrequire 'logger'\r\n\r\nActiveRecord::Base.establish_connection(adapter: 'postgresql', port: 5495)\r\n#ActiveRecord::Base.logger = Logger.new(STDOUT)\r\nActiveRecord::Schema.define do\r\n  create_table :people, temporary: true do |t|\r\n    t.string :name\r\n    t.boolean :deleted, null: false, default: false\r\n    t.timestamps null: false\r\n  end\r\n  create_table :emails, temporary: true do |t|\r\n    t.belongs_to :person\r\n    t.string :addr\r\n    t.boolean :deleted, null: false, default: false\r\n  end\r\nend\r\nif defined? ActiveSupport.halt_callback_chains_on_return_false=\r\n  ActiveSupport.halt_callback_chains_on_return_false = false\r\nend\r\n\r\nclass Person < ActiveRecord::Base\r\n  has_many :emails\r\n  \r\n  after_save do\r\n    # synchronize associated emails' deleted flag - FAIL HERE\r\n    emails.update_all(deleted: deleted?)\r\n    true\r\n  end\r\nend\r\nclass Email < ActiveRecord::Base\r\n  belongs_to :person\r\nend\r\n\r\nclass BugTest < Minitest::Test\r\n  # PASS - assign primary key BEFORE association\r\n  def test_pass1\r\n    person = Person.new\r\n    person.id = 10\r\n    person.name = 'FooBar'\r\n    person.emails = [Email.new(addr: 'test1@example.com')]\r\n    person.emails\r\n    person.save!\r\n    assert Person.find(10)\r\n  end\r\n  \r\n  # PASS - don't access association\r\n  def test_pass2\r\n    person = Person.new\r\n    person.name = 'FooBar'\r\n    person.emails = [Email.new(addr: 'test2@example.com')]\r\n    person.id = 11\r\n    person.save!\r\n    assert Person.find(11)\r\n  end\r\n  \r\n  # FAIL - assign primary key AFTER association, and then access association\r\n  def test_fail\r\n    person = Person.new\r\n    person.name = 'FooBar'\r\n    person.emails = [Email.new(addr: 'test3@example.com')]\r\n    person.id = 12\r\n    person.emails\r\n    person.save!\r\n    assert Person.find(12)\r\n  end\r\nend\r\n```\r\n\r\n### Expected behavior (Rails 4.2.6)\r\nAll tests passed.\r\n\r\n### Actual behavior (Rails 5.0.0 and master)\r\nTest `test_fail` failed with following error. Bind values for `UPDATE` SQL should be `[12]`, but empty.\r\n\r\n```\r\n  1) Error:\r\nBugTest#test_fail:\r\nActiveRecord::StatementInvalid: PG::ProtocolViolation: ERROR:  bind message supplies 0 parameters, but prepared statement \"\" requires 1\r\n: UPDATE \"emails\" SET \"deleted\" = 'f' WHERE \"emails\".\"person_id\" = $1\r\n    /home/tietew/.gem/ruby/2.3.0/bundler/gems/rails-19ff64d8f46d/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:601:in `async_exec'\r\n    /home/tietew/.gem/ruby/2.3.0/bundler/gems/rails-19ff64d8f46d/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:601:in `block in exec_no_cache'\r\n    /home/tietew/.gem/ruby/2.3.0/bundler/gems/rails-19ff64d8f46d/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:589:in `block in log'\r\n    /home/tietew/.gem/ruby/2.3.0/bundler/gems/rails-19ff64d8f46d/activesupport/lib/active_support/notifications/instrumenter.rb:21:in `instrument'\r\n    /home/tietew/.gem/ruby/2.3.0/bundler/gems/rails-19ff64d8f46d/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:583:in `log'\r\n    /home/tietew/.gem/ruby/2.3.0/bundler/gems/rails-19ff64d8f46d/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:601:in `exec_no_cache'\r\n    /home/tietew/.gem/ruby/2.3.0/bundler/gems/rails-19ff64d8f46d/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:588:in `execute_and_clear'\r\n    /home/tietew/.gem/ruby/2.3.0/bundler/gems/rails-19ff64d8f46d/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb:116:in `exec_delete'\r\n    /home/tietew/.gem/ruby/2.3.0/bundler/gems/rails-19ff64d8f46d/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:133:in `update'\r\n    /home/tietew/.gem/ruby/2.3.0/bundler/gems/rails-19ff64d8f46d/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `update'\r\n    /home/tietew/.gem/ruby/2.3.0/bundler/gems/rails-19ff64d8f46d/activerecord/lib/active_record/relation.rb:387:in `update_all'\r\n    test_update_all.rb:45:in `block in <class:Person>'\r\n    /home/tietew/.gem/ruby/2.3.0/bundler/gems/rails-19ff64d8f46d/activesupport/lib/active_support/callbacks.rb:396:in `instance_exec'\r\n    /home/tietew/.gem/ruby/2.3.0/bundler/gems/rails-19ff64d8f46d/activesupport/lib/active_support/callbacks.rb:396:in `block in make_lambda'\r\n    /home/tietew/.gem/ruby/2.3.0/bundler/gems/rails-19ff64d8f46d/activesupport/lib/active_support/callbacks.rb:207:in `block in halting_and_conditional'\r\n    /home/tietew/.gem/ruby/2.3.0/bundler/gems/rails-19ff64d8f46d/activesupport/lib/active_support/callbacks.rb:456:in `block in call'\r\n    /home/tietew/.gem/ruby/2.3.0/bundler/gems/rails-19ff64d8f46d/activesupport/lib/active_support/callbacks.rb:456:in `each'\r\n    /home/tietew/.gem/ruby/2.3.0/bundler/gems/rails-19ff64d8f46d/activesupport/lib/active_support/callbacks.rb:456:in `call'\r\n    /home/tietew/.gem/ruby/2.3.0/bundler/gems/rails-19ff64d8f46d/activesupport/lib/active_support/callbacks.rb:101:in `__run_callbacks__'\r\n    /home/tietew/.gem/ruby/2.3.0/bundler/gems/rails-19ff64d8f46d/activesupport/lib/active_support/callbacks.rb:755:in `_run_save_callbacks'\r\n    /home/tietew/.gem/ruby/2.3.0/bundler/gems/rails-19ff64d8f46d/activerecord/lib/active_record/callbacks.rb:298:in `create_or_update'\r\n    /home/tietew/.gem/ruby/2.3.0/bundler/gems/rails-19ff64d8f46d/activerecord/lib/active_record/persistence.rb:152:in `save!'\r\n    /home/tietew/.gem/ruby/2.3.0/bundler/gems/rails-19ff64d8f46d/activerecord/lib/active_record/validations.rb:50:in `save!'\r\n    /home/tietew/.gem/ruby/2.3.0/bundler/gems/rails-19ff64d8f46d/activerecord/lib/active_record/attribute_methods/dirty.rb:30:in `save!'\r\n    /home/tietew/.gem/ruby/2.3.0/bundler/gems/rails-19ff64d8f46d/activerecord/lib/active_record/transactions.rb:324:in `block in save!'\r\n    /home/tietew/.gem/ruby/2.3.0/bundler/gems/rails-19ff64d8f46d/activerecord/lib/active_record/transactions.rb:395:in `block in with_transaction_returning_status'\r\n    /home/tietew/.gem/ruby/2.3.0/bundler/gems/rails-19ff64d8f46d/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `block in transaction'\r\n    /home/tietew/.gem/ruby/2.3.0/bundler/gems/rails-19ff64d8f46d/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb:189:in `within_new_transaction'\r\n    /home/tietew/.gem/ruby/2.3.0/bundler/gems/rails-19ff64d8f46d/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `transaction'\r\n    /home/tietew/.gem/ruby/2.3.0/bundler/gems/rails-19ff64d8f46d/activerecord/lib/active_record/transactions.rb:211:in `transaction'\r\n    /home/tietew/.gem/ruby/2.3.0/bundler/gems/rails-19ff64d8f46d/activerecord/lib/active_record/transactions.rb:392:in `with_transaction_returning_status'\r\n    /home/tietew/.gem/ruby/2.3.0/bundler/gems/rails-19ff64d8f46d/activerecord/lib/active_record/transactions.rb:324:in `save!'\r\n    /home/tietew/.gem/ruby/2.3.0/bundler/gems/rails-19ff64d8f46d/activerecord/lib/active_record/suppressor.rb:46:in `save!'\r\n    test_update_all.rb:82:in `test_fail'\r\n```\r\n\r\n### System configuration\r\n**Rails version**: 5.0.0 and master\r\n\r\n**Ruby version**: 2.3.1\r\n\r\n**PostgreSQL version**: 9.5.1\r\n"}}
{"actor":{"display_login":"rafaelfranca"}}