Skip to content

An error for test_has_many_through_polymorphic_has_one with Oracle #5636

Closed
yahonda opened this Issue Mar 28, 2012 · 2 comments

3 participants

@yahonda
yahonda commented Mar 28, 2012

Since Rails 3.2.3.rc1 has been released, I've tested ActiveRecord unit tests with oracle-enhanced and found
the following error.

$ ARCONN=oracle ruby -Itest test/cases/associations/join_model_test.rb -n 'test_has_many_through_polymorphic_has_one'
Using oracle with Identity Map off
Run options: -n test_has_many_through_polymorphic_has_one

# Running tests:

E

Finished tests in 32.721906s, 0.0306 tests/s, 0.0000 assertions/s.

  1) Error:
test_has_many_through_polymorphic_has_one(AssociationsJoinModelTest):
ActiveRecord::StatementInvalid: OCIError: ORA-00918: column ambiguously defined: SELECT "TAGGINGS".* FROM "TAGGINGS" INNER JOIN "POSTS" ON "TAGGINGS"."TAGGABLE_ID" = "POSTS"."ID" AND "TAGGINGS"."TAGGABLE_TYPE" = 'Post' WHERE "POSTS"."AUTHOR_ID" = 1 ORDER BY id
    stmt.c:235:in oci8lib_191.so
    /home/yahonda/.rvm/gems/ruby-1.9.3-p125@v323/gems/ruby-oci8-2.1.0/lib/oci8/oci8.rb:447:in `exec'
    /home/yahonda/Dropbox/git/oracle-enhanced/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:143:in `exec'
    /home/yahonda/Dropbox/git/oracle-enhanced/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:627:in `block in exec_query'
    /home/yahonda/Dropbox/git/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
    /home/yahonda/Dropbox/git/rails/activesupport/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    /home/yahonda/Dropbox/git/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
    /home/yahonda/Dropbox/git/oracle-enhanced/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:1310:in `log'
    /home/yahonda/Dropbox/git/oracle-enhanced/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:607:in `exec_query'
    /home/yahonda/Dropbox/git/oracle-enhanced/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:1264:in `select'
    /home/yahonda/Dropbox/git/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:18:in `select_all'
    /home/yahonda/Dropbox/git/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:63:in `select_all'
    /home/yahonda/Dropbox/git/rails/activerecord/lib/active_record/querying.rb:38:in `block in find_by_sql'
    /home/yahonda/Dropbox/git/rails/activerecord/lib/active_record/explain.rb:40:in `logging_query_plan'
    /home/yahonda/Dropbox/git/rails/activerecord/lib/active_record/querying.rb:37:in `find_by_sql'
    /home/yahonda/Dropbox/git/rails/activerecord/lib/active_record/relation.rb:171:in `exec_queries'
    /home/yahonda/Dropbox/git/rails/activerecord/lib/active_record/relation.rb:160:in `block in to_a'
    /home/yahonda/Dropbox/git/rails/activerecord/lib/active_record/explain.rb:40:in `logging_query_plan'
    /home/yahonda/Dropbox/git/rails/activerecord/lib/active_record/relation.rb:159:in `to_a'
    /home/yahonda/Dropbox/git/rails/activerecord/lib/active_record/relation.rb:491:in `=='

1 tests, 0 assertions, 0 failures, 1 errors, 0 skips
[yahonda@worksl6 activerecord

It looks #5557 implements .order(:id) at the end of statement, which is not compatible with Oracle.

   def test_has_many_through_polymorphic_has_one
    assert_equal Tagging.find(1,2).sort_by { |t| t.id }, authors(:david).tagging.order(:id)
   end

By changing as follows, it works both with PostgreSQL and Oracle.

   def test_has_many_through_polymorphic_has_one
    assert_equal Tagging.find(1,2).sort_by { |t| t.id }, authors(:david).tagging.order('taggings.id')
   end

However Usually, I open a pull request for master branch first, however similar commits have been made for 3-2-stable(b332891), 3-1-stable(51bb1c1) and 3-0-stable (a9fdefd) not for master.

@carlosantoniodasilva
Ruby on Rails member

@yahonda yes, I think you're right. It all depends on how the query is constructed, as it's doing a join it'd fail hard to pick the right id to order given the table name is not specified.

This was only sent to 3.x branches because the issue only happens under Ruby 1.8.7 with its unordered hashes, depending on how fixtures are loaded.

Could you send a PR to fix that for 3.2? I think it'll apply cleanly to other branches then. Thanks.

@yahonda
yahonda commented Mar 28, 2012

@carlosantoniodasilva

Thank you for the clear explanation, I understand the original issue happens just with Ruby 1.8.7
but the next Rails (probably 4) will not support Ruby 1.8.7, this fix is not required.

I'm going to open a pull request for 3.2 branch.

@fxn fxn closed this Mar 28, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.