jackc / edge

Edge provides graph functionality to ActiveRecord.
MIT License
90 stars 10 forks source link

PG::ProtocolViolation #14

Closed hx closed 8 years ago

hx commented 9 years ago

Some have suggested https://github.com/rails/rails/issues/20236 is caused by edge unscoping and re-binding values around https://github.com/jackc/edge/blob/master/lib/edge/forest.rb#L97-L102. Is there another way to achieve this?

hx commented 9 years ago

Closed by PR https://github.com/jackc/edge/pull/15

TheKidCoder commented 8 years ago

I am still running into this on jRuby. MRI seems to be fine though.

[11] pry(main)> ActiveRecord.version
=> Gem::Version.new("4.2.5")
[12] pry(main)> exit
~reppro|rails4.2⚡ ⇒ rails c
Loading development environment (Rails 4.2.5)
[1] pry(main)> ActiveRecord.version
=> Gem::Version.new("4.2.5")
[2] pry(main)> Edge::VERSION
=> "0.4.3"
[4] pry(main)> Prompt.where(name: "Universal Questions").find_forest
  Prompt Load (3.0ms)  WITH RECURSIVE "all_nodes" AS ( SELECT "prompts"."id", "prompts"."parent_id" FROM "prompts" WHERE "prompts"."name" = ? UNION SELECT "prompts"."id", "prompts"."parent_id" FROM "prompts" INNER JOIN "all_nodes" ON "prompts"."parent_id" = "all_nodes"."id" ) SELECT * FROM "all_nodes" INNER JOIN "prompts" ON "all_nodes"."id" = "prompts"."id"  ORDER BY position
ActiveRecord::StatementInvalid: ActiveRecord::JDBCError: org.postgresql.util.PSQLException: ERROR: bind message supplies 0 parameters, but prepared statement "" requires 1: WITH RECURSIVE "all_nodes" AS ( SELECT "prompts"."id", "prompts"."parent_id" FROM "prompts" WHERE "prompts"."name" = ? UNION SELECT "prompts"."id", "prompts"."parent_id" FROM "prompts" INNER JOIN "all_nodes" ON "prompts"."parent_id" = "all_nodes"."id" ) SELECT * FROM "all_nodes" INNER JOIN "prompts" ON "all_nodes"."id" = "prompts"."id"  ORDER BY position
from arjdbc/jdbc/RubyJdbcConnection.java:888:in `execute_query'

I think the culprit may be: https://github.com/jackc/edge/blob/master/lib/edge/forest.rb#L56

jackc commented 8 years ago

I don't have a JRuby install handy at the moment. Do the tests pass on JRuby?

jackc commented 8 years ago

I installed JRuby and there are failing tests revealing this problem. It turns out that the MRI pg gem and JRuby's PostgreSQL adapter process bind variables at different times. It's a bit of a hack but edge now tries to detect JRuby and handle binds differently.

Just released v0.4.4 with the fix.

TheKidCoder commented 8 years ago

Awesome! Thanks, sorry I didn't see your earlier response.