Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix SchemaStatements#initialize_type_map
Since the Rails 6 upgrade, we started seeing some random PostGIS serialization/deserialization issues, debugging the issues shows that the ActiveRecord connection `type_map` isn't initialized properly which leave the custom `ActiveRecord::ConnectionAdapters::PostGIS::SpatialColumn` with no mapping for its PostGIS OID. Usually, Rails would add missing OID mappings when encountered, however, in that particular code path, it does not happen and because of the way `super` is done, that happens too late. Another issue in Rails must also be fixed, but that's another story :) This patch fixes the `SchemaStatements#initialize_type_map` method by ensuring that the specific PostGIS types are registered before calling `super` which will then call `load_additional_types` and registers the other PostGIS OIDs. That way the custom column will be properly initialized and be present in the `type_map` cache. Some code references: - The `initialize_type_map` activerecord-postgis-adapter method overwritten https://github.com/rgeo/activerecord-postgis-adapter/blob/cc0e3f53520feed0b43800d8ee86561ee03de413/lib/active_record/connection_adapters/postgis/schema_statements.rb#L87-L105 - the `load_additional_types` method in Rails: https://github.com/rails/rails/blob/8d57cb39a88787bb6cfb7e1c481556ef6d8ede7a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb#L593 - the `get_oid_type` method in Rails that lazy load the type: https://github.com/rails/rails/blob/8d57cb39a88787bb6cfb7e1c481556ef6d8ede7a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb#L514-L516 - the `lookup_cast_type_from_column` method in Rails that does not lazy load the type: https://github.com/rails/rails/blob/15748f6a052d4df68b6acf66456c181b42d9fe25/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb#L78 This patch should solve rgeo#307 and rgeo#308.
- Loading branch information