ActiveRecord errors with Rails 4 and Postgres
benwalsh opened this issue · comments
I'm running Ruby 2.0.0p195, Rails 4.0.0, geokit 1.6.5, geokit-rails 2.0.0 (master), Postgres 9.2.4, pg gem 0.15.1.
I have a zip_codes table which has :latitude and :longitude columns both of PostgresQL type "float".
class ZipCode < ActiveRecord::Base
acts_as_mappable :lat_column_name => :latitude, :lng_column_name => :longitude
and
class Item < ActiveRecord::Base
belongs_to :zip_code
acts_as_mappable :through => :zip_code
Without the acts_as_mappable
, all the associations work fine. With them, the associations blow up. It seems to me that the Postgres ordered arguments ($1
, $2
, etc) are involved somehow. I get errors like this:
Item.all.map(&:zip_code)
#<ZipCode:0x007fb820efaaf8>
ActiveRecord::StatementInvalid: PG::Error: ERROR: could not determine data type of parameter $1
: SELECT "zip_codes".* FROM "zip_codes" WHERE "zip_codes"."id" = $7 ORDER BY "zip_codes"."id" ASC LIMIT 1
it's as if the numbered arguments haven't been "reset" to $1
, or something? I'm not entirely sure. Anyone else had this issue, or anything like it?
Yep, same here. It happens for simple things like Model.count for me, but not always. Pretty terrible bug.
Getting the same thing here as well :( any workarounds yet?
The test suite fails if you run it with Rails 4 on your local machine for all databases.
@mnoack I have time to try and fix this, but I have no idea where to start.
Sorry these messages got lost in my inbox. Let's focus first on getting Rails 4 support with the existing tests, and once that's running adding postgres testing to travis. I've changed .travis.yml so Rails 3 and Rails 4
I've ran many of the tests with rails 4 and they work individually. It seems some of the overly complex parts of geokit-rails should be removed (there are parts that override core arel for example) that are probably the culprit. I've tried to keep them in for backwards compatibility but have always cringed at overriding activerecord/arel the way we have.
I've uploaded some MASSIVE changes to a rails 4 branch.
The changes are in no way related to rails 4 but stop all the active record/arel modifications which both simplifies the code and thus not surprisingly more flexible with other rails versions.
There's still 3 failing tests which looks like a sqlite3 bug where ".last" on the arel instead of replacing "ASC" with "DESC" it adds "DESC" in 2 places (how weird!).
Can you guys try with postgres and/or another database to see how that goes.
If all is good perhaps you can clean up all the commented out code, etc and submit a pull request.
TESTING:
I'm a big testing advocate. When I came onto this project tests didn't work and we weren't using continuous integration (we're now using travis-ci.org).
If one of you could read this doc and get mysql and/or postgres passing that would be great:
http://about.travis-ci.org/docs/user/database-setup/
Bump to @kurtisnelson @benwalsh @NealKemp
big high-five to @mnoack -- I am going to try to recreate this issue again (ended up finding a workaround) and try to test new code in Postgres
@NealKemp I'll be honest. I've never used postgres and don't know how to start so I'm hoping with the rails4 stuff now merged in (thanks alot for that) you'll be able to let me know if there's anything more to deal with this issue.
@benwalsh / @kurtisnelson two things that should fix this:
- Use
to_a
instead ofall
- Use the 2.0.0 release I have a test suite around it in my app and have been using the new stuff in production for a few weeks now. I haven't seen any issues.