Bug #271
tests fail with postgresql as backend
| Status : | Closed | Start : | ||
| Priority : | Urgent | Due date : | ||
| Assigned to : | tobi - | % Done : | 0% |
|
| Category : | frontend | |||
| Target version : | release2 | |||
| Resolution : | fixed |
Description
When you type "rake" to test units and functions against typo backed with PostgreSQL DBMS some tests fail due to referential integrity constraints. Here the traceback:
test_send_pings(ArticleTest):
ActiveRecord::StatementInvalid: ERROR: update or delete on "articles" violates foreign key constraint "$1" on "pings"
DETAIL: Key (id)=(1) is still referenced from table "pings".
: DELETE FROM articles
/usr/lib/ruby/gems/1.8/gems/activerecord-1.10.1/lib/active_record/connection_adapters/abstract_adapter.rb:422:in @log'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.10.1/lib/active_record/connection_adapters/postgresql_adapter.rb:86:in @delete'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.10.1/lib/active_record/fixtures.rb:264:in @delete_existing_fixtures'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.10.1/lib/active_record/fixtures.rb:226:in @create_fixtures'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.10.1/lib/active_record/fixtures.rb:226:in @each'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.10.1/lib/active_record/fixtures.rb:226:in @create_fixtures'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.10.1/lib/active_record/fixtures.rb:225:in @transaction'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.10.1/lib/active_record/fixtures.rb:225:in @create_fixtures'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.10.1/lib/active_record/fixtures.rb:475:in @load_fixtures'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.10.1/lib/active_record/fixtures.rb:432:in @setup_with_fixtures'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.10.1/lib/active_record/fixtures.rb:457:in @setup'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.10.1/lib/active_record/fixtures.rb:456:in @setup'
1) Error:
and for test_functional
test_mt_get_recent_post_titles(BackendControllerTest):
ActiveRecord::StatementInvalid: ERROR: update or delete on "categories" violates foreign key constraint "$2" on "articles_categories"
DETAIL: Key (id)=(1) is still referenced from table "articles_categories".
: DELETE FROM categories
/usr/lib/ruby/gems/1.8/gems/activerecord-1.10.1/lib/active_record/connection_adapters/abstract_adapter.rb:422:in @log'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.10.1/lib/active_record/connection_adapters/postgresql_adapter.rb:86:in @delete'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.10.1/lib/active_record/fixtures.rb:264:in @delete_existing_fixtures'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.10.1/lib/active_record/fixtures.rb:226:in @create_fixtures'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.10.1/lib/active_record/fixtures.rb:226:in @each'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.10.1/lib/active_record/fixtures.rb:226:in @create_fixtures'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.10.1/lib/active_record/fixtures.rb:225:in @transaction'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.10.1/lib/active_record/fixtures.rb:225:in @create_fixtures'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.10.1/lib/active_record/fixtures.rb:475:in @load_fixtures'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.10.1/lib/active_record/fixtures.rb:432:in @setup_with_fixtures'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.10.1/lib/active_record/fixtures.rb:457:in @setup'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.10.1/lib/active_record/fixtures.rb:456:in @setup'
This is due the internal checks postgres does using foreign keys constraints. By default it uses the "NO ACTION" action for both DELETE and UPDATE statements. This means that it produces a foreign key constraint violation every time it tries to delete an associated table. The aim of foreign keys is to let the DBMS handle all relations (one-to-many and many-to-many) by itself in the correct way. When the test process issues DELETE statements to empty the test tables postgres sees that he's trying to delete a table (in the first case "articles") that has associated tables ("pings") and hence raise an error. In our case no "ping" could exists without an "article" (the same for other one-to-many and many-to-many associations) so we must tell postgres that when we want to delete a master table ("articles") we should delete all associated data as well.
I wrote a patch for the schema.psql.sql file, re-created the development db, issued rake command all gone well. Started a typo instance with the new schema, played with articles/categories deletion in the backend and all gone well.
HTH
Lawrence Oluyede
