evilmartians / evil-seed

A Gem for creating partial anonymized dumps of your database using your app model relations.
MIT License
447 stars 19 forks source link

Invalid SQL order by clause from root model configuration #7

Closed andyatkinson closed 5 years ago

andyatkinson commented 5 years ago

With no Evil Seed configuration on the root model, just the model name, it seems like the SQL being generated includes an ORDER BY with the table name and then no field name, which is invalid, this bit: ORDER BY "users"."" ASC.

EvilSeed.configure do |config|
  config.root('User') do |root|
  end
end
EvilSeed.dump(File.join(__dir__, "dump.sql").to_s)

I'm getting this kind of error:

ActiveRecord::StatementInvalid: ActiveRecord::JDBCError: org.postgresql.util.PSQLException: ERROR: zero-length delimited identifier at or near """"
  Position: 50: SELECT  "users".* FROM "users"  ORDER BY "users"."" ASC LIMIT 1000

Rails 4.2.11, Jruby 9.2.5.0, I have hacked the in_batches to be find_in_batches locally, which I don't think is related. Do you know where this order by clause is coming in? Do you have a suggestion on how to get it removed? Without the order by clause, the rest of the statement is valid.

andyatkinson commented 5 years ago

I debugged this and it seems to be from trying to use a workaround of find_in_batches instead of in_batches in the relation dumper class, so I'm closing this issue since it's not related to released code. I have opened a separate issue about the refinement back port to rails 4.2 not working for me, which may be because we're using jruby and it's not supported, that issue is here: https://github.com/evilmartians/evil-seed/issues/6