Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostgreSQL bind errors when including polymorphic associations #16591

Closed
dmarkow opened this issue Aug 20, 2014 · 2 comments
Closed

PostgreSQL bind errors when including polymorphic associations #16591

dmarkow opened this issue Aug 20, 2014 · 2 comments

Comments

@dmarkow
Copy link
Contributor

dmarkow commented Aug 20, 2014

Test Case: https://gist.github.com/dmarkow/c27d00bc4fb030f2dce5

With this setup:

class Post < ActiveRecord::Base
  has_many :comments
  has_many :notes, as: :notable
end

class Note < ActiveRecord::Base
  belongs_to :notable, polymorphic: true
end

class Comment < ActiveRecord::Base
  belongs_to :post
end

and a test case that does this:

Post.includes(:comments).order("comments.category").first
Post.includes(:notes).order("notes.category").first

the first (non-polymorphic) line works fine, but the second one raises this:

BugTest#test_association_stuff:
ActiveRecord::StatementInvalid: PG::ProtocolViolation: ERROR:  bind message supplies 0 parameters, but prepared statement "" requires 1
: SELECT  DISTINCT "posts"."id", notes.category AS alias_0 FROM "posts" LEFT OUTER JOIN "notes" ON "notes"."notable_id" = "posts"."id" AND "notes"."notable_type" = $1  ORDER BY notes.category LIMIT 1

This came up when trying out the 4.2.0 beta, and it happens on the master branch too. Works perfectly fine through 4.1.5.

I searched and the only recent issue that seems to be possibly related is #15821

@dmarkow dmarkow changed the title Postgresql bind errors when including polymorphic associations PostgreSQL bind errors when including polymorphic associations Aug 20, 2014
@girishso
Copy link
Contributor

bug confirmed in latest master, works in 4.1.5

looking into it, will update my findings

@chancancode
Copy link
Member

Fixed in a8827cb. Thank you so much for trying the beta and catching this bug. The reproduction steps were very helpful! ❤️

trungpham pushed a commit to trungpham/rails that referenced this issue Sep 18, 2014
This is cased by 03118bc + 9b5d603. The first commit referenced the undefined
local variable `column` when it should be using `reflection.type` as the lookup
key. The second commit changed `build_arel` to not modify the `bind_values` in-
place so we need to combine the arel's `bind_values` with the relation's when
building the SQL.

Fixes rails#16591

Related rails#15821 / rails#15892 / 7aeca50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants