Skip to content

All of StoreTest get errors with Oracle database which handles empty strings '' as NULL. #7138

Closed
yahonda opened this Issue Jul 23, 2012 · 10 comments

2 participants

@yahonda
yahonda commented Jul 23, 2012

All of StoreTest get errors with Oracle database which handles empty strings '' as NULL.

$ ARCONN=oracle ruby -Itest test/cases/store_test.rb
Using oracle
Run options: --seed 10396

# Running tests:

EEEEEEEEEEEEEEEEEE

Finished tests in 1.056618s, 17.0355 tests/s, 0.0000 assertions/s.

  1) Error:
test_0001_reading store attributes through accessors(StoreTest):
ActiveRecord::StatementInvalid: OCIError: ORA-01400: cannot insert NULL into ("ARUNIT"."ADMIN_USERS"."PREFERENCES"): INSERT INTO "ADMIN_USERS" ("NAME", "ID", "ACCOUNT_ID") VALUES ('David', 127326141, 330255392)
    stmt.c:253:in oci8lib_191.so
    /home/yahonda/.rvm/gems/ruby-1.9.3-p194@railsmaster/gems/ruby-oci8-2.1.2/lib/oci8/oci8.rb:474:in `exec'
    /home/yahonda/.rvm/gems/ruby-1.9.3-p194@railsmaster/gems/ruby-oci8-2.1.2/lib/oci8/oci8.rb:282:in `exec_internal'
    /home/yahonda/.rvm/gems/ruby-1.9.3-p194@railsmaster/gems/ruby-oci8-2.1.2/lib/oci8/oci8.rb:275:in `exec'
    /home/yahonda/git/oracle-enhanced/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:471:in `exec'
    /home/yahonda/git/oracle-enhanced/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:88:in `exec'
    /home/yahonda/git/oracle-enhanced/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:607:in `block in execute'
    /home/yahonda/git/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:288:in `block in log'
    /home/yahonda/git/rails/activesupport/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    /home/yahonda/git/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:283:in `log'
    /home/yahonda/git/oracle-enhanced/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:1325:in `log'
    /home/yahonda/git/oracle-enhanced/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:607:in `execute'
    /home/yahonda/git/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:278:in `insert_fixture'
    /home/yahonda/git/oracle-enhanced/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:864:in `insert_fixture'
    /home/yahonda/git/rails/activerecord/lib/active_record/fixtures.rb:475:in `block (5 levels) in create_fixtures'
    /home/yahonda/git/rails/activerecord/lib/active_record/fixtures.rb:474:in `each'
    /home/yahonda/git/rails/activerecord/lib/active_record/fixtures.rb:474:in `block (4 levels) in create_fixtures'
    /home/yahonda/git/rails/activerecord/lib/active_record/fixtures.rb:473:in `each'
    /home/yahonda/git/rails/activerecord/lib/active_record/fixtures.rb:473:in `block (3 levels) in create_fixtures'
    /home/yahonda/git/rails/activerecord/lib/active_record/fixtures.rb:465:in `each'
    /home/yahonda/git/rails/activerecord/lib/active_record/fixtures.rb:465:in `block (2 levels) in create_fixtures'
    /home/yahonda/git/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:193:in `transaction'
    /home/yahonda/git/rails/activerecord/lib/active_record/fixtures.rb:464:in `block in create_fixtures'
    /home/yahonda/git/oracle-enhanced/lib/active_record/connection_adapters/oracle_enhanced_schema_statements_ext.rb:208:in `disable_referential_integrity'
    /home/yahonda/git/rails/activerecord/lib/active_record/fixtures.rb:451:in `create_fixtures'
    /home/yahonda/git/rails/activerecord/lib/active_record/fixtures.rb:888:in `load_fixtures'
    /home/yahonda/git/rails/activerecord/lib/active_record/fixtures.rb:842:in `setup_fixtures'
    /home/yahonda/git/rails/activesupport/lib/active_support/callbacks.rb:342:in `_run__631894265428328416__setup__callbacks'
    /home/yahonda/git/rails/activesupport/lib/active_support/callbacks.rb:75:in `run_callbacks'
    /home/yahonda/git/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:26:in `before_setup'

... snip ...
18 tests, 0 assertions, 0 failures, 18 errors, 0 skips
$

See https://gist.github.com/3165493 for details.

  • These errors introduced since #4856 has been merged.
  • These errors exist only if the database which handles empty strings '' as NULL.

I've been thinking / investigating this error at my environment but I have no idea how to address these errors
and #4840 , that is the original case addressed by #4856.

@yahonda
yahonda commented Jul 24, 2012

It also causes FoxyFixturesTest failures. See here for detail.

@yahonda
yahonda commented Jul 26, 2012

I found these failures can be addressed by adding preferences: foobar at the users.yml fixture file.

  • test/fixtures/admin/users.yml
david:
  name: David
  account: signals37
  preferences: foobar

jamis:
  name: Jamis
  account: signals37

I think it should be a good fix for the FoxyFixturesTest failures because this test had been added before the store_test implemented.

Though, store_test specifies the preferences attribute with :default => "". This :default => "" setting never used at the FoxyFixturesTest tests.

@rafaelfranca
Ruby on Rails member

Which is the serialize class of preferences?

Can we a real value to preferences? E.g if it is a hash, something like "{color => blue}" (I don't remember how Active Record serializes a hash)

@yahonda
yahonda commented Jul 26, 2012

@rafaelfranca Thanks for the comment. foobar must be some real hash value as you pointed out. I'll fix it when open a pull request.

My question is using fixtures for the attribute with :default => "". It would expect a empty string should be used for this attribute as a default. Fixtures override this default value. If :default => "" is mandatory, I need to find another way to address it.

@rafaelfranca
Ruby on Rails member

This seems very odd. I would expect that david fixture should use the default value.

@yahonda
yahonda commented Jul 26, 2012

Agreed. So I did not open a pull request yet.

As you may (may not) know the big concern is Oracle database handles the empty string as NULL. Therefore it cannot support :default => "" and :null => false both.

@yahonda
yahonda commented Jul 26, 2012

I've made a reproduce_4856 branch to see if both :default => "" and :null => true are mandatory to address #4856.

This branch has been made from the commit 2abaa19e77d1097730cfa6e0924ee7c1660ac01f and remove the implantation code from this commit and bumped journey version to resolve bundle update errors.

@yahonda
yahonda commented Jul 27, 2012

The original issue TypeError: can't convert Symbol into Integer
reproduces when :null => true for all sqlite3, postgresql, mysql, mysql2 and oracle enhanced adapters.

Although It did not reproduce for mysql and mysql2 adapters when the :preferences datatype was text,
Since the commit a9721d8 changes this datatype to string, it reproduces with mysql and mysql2 adapters also. #4856 had been addressed before the a9721d8 merged.

You can see the test case and test results.

On top of the commit above, the commit has been applied, the original issue has been addressed for all sqlite3, postgresql, mysql, mysql2 and oracle enhanced adapters.

You can see the test case and test results.

Bottom line: I think this ORA-01400 errors can be addressed by changing :null => true. No fixture / default value change required.

@yahonda
yahonda commented Jul 27, 2012

Opened a pull request #7173.

@yahonda
yahonda commented Jul 27, 2012

#7173 has been merged to the master.

@yahonda yahonda closed this Jul 27, 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.