ActiveRecord::StatementInvalid: OCIError: ORA-01400: cannot insert NULL into ("ARUNIT"."ADMIN_USERS"."PREFERENCES") since pull request #4856 #6108

Closed
yahonda opened this Issue May 2, 2012 · 1 comment

Comments

Projects
None yet
1 participant
@yahonda
Contributor

yahonda commented May 2, 2012

Since pull request #4856 has been merged to the rails-master branch,
23 unit tests got a ActiveRecord::StatementInvalid: OCIError: ORA-01400 error when tested with Oracle.

This is based on current Oracle implementation, which handles a character value with a length of zero as null.
See here for detail.

Here is one of 23 test with errors.

ARCONN=oracle ruby -Itest test/cases/fixtures_test.rb -n test_automatically_sets_primary_key
Using oracle
Run options: -n test_automatically_sets_primary_key --seed 2675

# Running tests:

E

Finished tests in 4.355216s, 0.2296 tests/s, 0.0000 assertions/s.

  1) Error:
test_automatically_sets_primary_key(FoxyFixturesTest):
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:609: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:18: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:1326:in `log'
    /home/yahonda/git/oracle-enhanced/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:609:in `execute'
    /home/yahonda/git/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:277:in `insert_fixture'
    /home/yahonda/git/oracle-enhanced/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:866:in `insert_fixture'
    /home/yahonda/git/rails/activerecord/lib/active_record/fixtures.rb:473:in `block (5 levels) in create_fixtures'
    /home/yahonda/git/rails/activerecord/lib/active_record/fixtures.rb:472:in `each'
    /home/yahonda/git/rails/activerecord/lib/active_record/fixtures.rb:472:in `block (4 levels) in create_fixtures'
    /home/yahonda/git/rails/activerecord/lib/active_record/fixtures.rb:471:in `each'
    /home/yahonda/git/rails/activerecord/lib/active_record/fixtures.rb:471:in `block (3 levels) in create_fixtures'
    /home/yahonda/git/rails/activerecord/lib/active_record/fixtures.rb:463:in `each'
    /home/yahonda/git/rails/activerecord/lib/active_record/fixtures.rb:463:in `block (2 levels) in create_fixtures'
    /home/yahonda/git/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
    /home/yahonda/git/rails/activerecord/lib/active_record/fixtures.rb:462: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:447:in `create_fixtures'
    /home/yahonda/git/rails/activerecord/lib/active_record/fixtures.rb:887:in `load_fixtures'
    /home/yahonda/git/rails/activerecord/lib/active_record/fixtures.rb:841:in `setup_fixtures'
    /home/yahonda/git/rails/activesupport/lib/active_support/callbacks.rb:348:in `_run__1339812566902401413__setup__callbacks'
    /home/yahonda/git/rails/activesupport/lib/active_support/callbacks.rb:80:in `run_callbacks'
    /home/yahonda/git/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:28:in `run'

1 tests, 0 assertions, 0 failures, 1 errors, 0 skips
$

At the table definition, data_default column shows '' as expected
but when insert statement executed Oracle handles '' as null, then this column

SQL> select table_name,column_name,data_type,DATA_DEFAULT,NULLABLE
  2  from user_tab_columns
  3  where table_name = 'ADMIN_USERS'
  4  and column_name = 'PREFERENCES'
  5  /

TABLE_NAME   COLUMN_NAME      DATA_TYPE    DATA_DEFAULT     NULLABLE
---------------- ---------------- ---------------- -------------------- ----------
ADMIN_USERS  PREFERENCES      CLOB         ''           N

SQL> 

I understand these errors are caused by non standard implementation, however it is what it is.
As of right now, I have no good way to resolve this errors without causing any regressions to other database adapters(sqlite3, mysql, mysql2 and postgresql).

It would be very helpful if someone has comments/suggestions.

@yahonda

This comment has been minimized.

Show comment Hide comment
@yahonda

yahonda Jul 23, 2012

Contributor

#7138 shows the affected test case clearly. This issue should be closed.

Contributor

yahonda commented Jul 23, 2012

#7138 shows the affected test case clearly. This issue should be closed.

@yahonda yahonda closed this Jul 23, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment