Skip to content
Browse files

reloading type map on extension changing

  • Loading branch information...
1 parent 95e87bf commit efd2be35510af7b02e70e4c5939720d7b12bc1c1 @tenderlove tenderlove committed Jan 29, 2013
View
4 activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
@@ -239,6 +239,10 @@ def [](oid)
@mapping[oid]
end
+ def clear
+ @mapping.clear
+ end
+
def key?(oid)
@mapping.key? oid
end
View
13 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -586,11 +586,15 @@ def supports_ranges?
end
def enable_extension(name)
- exec_query "CREATE EXTENSION IF NOT EXISTS #{name}"
+ exec_query("CREATE EXTENSION IF NOT EXISTS #{name}").tap {
+ reload_type_map
+ }
end
def disable_extension(name)
- exec_query "DROP EXTENSION IF EXISTS #{name} CASCADE"
+ exec_query("DROP EXTENSION IF EXISTS #{name} CASCADE").tap {
+ reload_type_map
+ }
end
def extension_enabled?(name)
@@ -666,6 +670,11 @@ def translate_exception(exception, message)
private
+ def reload_type_map
+ OID::TYPE_MAP.clear
+ initialize_type_map
+ end
+
def initialize_type_map
result = execute('SELECT oid, typname, typelem, typdelim, typinput FROM pg_type', 'SCHEMA')
leaves, nodes = result.partition { |row| row['typelem'] == '0' }

1 comment on commit efd2be3

@yahonda

According to git bisect output, this commit looks cause some failures with PostgreSQL 9.2.2.

$ cd activerecord
$ ARCONN=postgresql ruby -Itest test/cases/adapters/postgresql/hstore_test.rb
Using postgresql
Run options: --seed 34198

# Running tests:

............unknown OID: tags(2249705) (SELECT  "hstores".* FROM "hstores"  WHERE "hstores"."id" = $1 LIMIT 1)
F.......unknown OID: tags(2249705) (SELECT  "hstores".* FROM "hstores"  WHERE "hstores"."id" = $1 LIMIT 1)
Funknown OID: tags(2249705) (SELECT  "hstores".* FROM "hstores"  WHERE "hstores"."id" = $1 LIMIT 1)
Funknown OID: tags(2249705) (SELECT  "hstores".* FROM "hstores"   ORDER BY "hstores"."id" ASC LIMIT 1)
.unknown OID: tags(2249705) (SELECT  "hstores".* FROM "hstores"   ORDER BY "hstores"."id" ASC LIMIT 1)
Funknown OID: tags(2249705) (SELECT  "hstores".* FROM "hstores"   ORDER BY "hstores"."id" ASC LIMIT 1)
F.unknown OID: tags(2249705) (SELECT  "hstores".* FROM "hstores"  WHERE "hstores"."id" = $1 LIMIT 1)
F

Finished tests in 0.820261s, 32.9163 tests/s, 45.1076 assertions/s.

  1) Failure:
test_nil(PostgresqlHstoreTest) [test/cases/adapters/postgresql/hstore_test.rb:138]:
Expected: {"a"=>nil}
  Actual: "\"a\"=>NULL"

  2) Failure:
test_quotes(PostgresqlHstoreTest) [test/cases/adapters/postgresql/hstore_test.rb:142]:
--- expected
+++ actual
@@ -1 +1 @@
-{"a"=>"b\"ar", "1\"foo"=>"2"}
+"\"a\"=>\"b\\\"ar\", \"1\\\"foo\"=>\"2\""


  3) Failure:
test_quoting_special_characters(PostgresqlHstoreTest) [test/cases/adapters/postgresql/hstore_test.rb:162]:
--- expected
+++ actual
@@ -1 +1 @@
-{"ca"=>"cA?", "ac"=>"A?c"}
+"\"ac\"=>\"A?c\", \"ca\"=>\"cA?\""


  4) Failure:
test_select(PostgresqlHstoreTest) [test/cases/adapters/postgresql/hstore_test.rb:124]:
Expected: {"1"=>"2"}
  Actual: "\"1\"=>\"2\""

  5) Failure:
test_select_multikey(PostgresqlHstoreTest) [test/cases/adapters/postgresql/hstore_test.rb:130]:
Expected: {"1"=>"2", "2"=>"3"}
  Actual: "\"1\"=>\"2\", \"2\"=>\"3\""

  6) Failure:
test_whitespace(PostgresqlHstoreTest) [test/cases/adapters/postgresql/hstore_test.rb:146]:
--- expected
+++ actual
@@ -1 +1 @@
-{"a b"=>"b ar", "1\"foo"=>"2"}
+"\"a b\"=>\"b ar\", \"1\\\"foo\"=>\"2\""


27 tests, 37 assertions, 6 failures, 0 errors, 0 skips
  • Environment
$ ruby -v
ruby 1.9.3p374 (2013-01-15 revision 38858) [x86_64-linux]
$ gem list pg

*** LOCAL GEMS ***

pg (0.14.1)
$ psql -d activerecord_unittest
psql (9.2.2)
Type "help" for help.

activerecord_unittest=# select version();
                                                   version
--------------------------------------------------------------------------------------------------------------
 PostgreSQL 9.2.2 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.4.6 20120305 (Red Hat 4.4.6-4), 64-bit
(1 row)

activerecord_unittest=# \q
$
  • git bisect result
$ git bisect bad
efd2be35510af7b02e70e4c5939720d7b12bc1c1 is the first bad commit
commit efd2be35510af7b02e70e4c5939720d7b12bc1c1
Author: Aaron Patterson <aaron.patterson@gmail.com>
Date:   Tue Jan 29 15:49:21 2013 -0800

    reloading type map on extension changing

:040000 040000 d4352c96b2bd1621dcc75924c6ecd1288850cccd aa3401da99b94c87788d2a6c34df02265e94afaf M      activerecord
Please sign in to comment.
Something went wrong with that request. Please try again.