I'm using columns of type "geography" for some few "point within polygon" queries. They are too few and too simple to bundle a GIS gem, I handle it all on the SQL level.
However, every time Rails boots (rake tasks, console etc), the following warning is spit:
unknown OID 17227: failed to recognize type of 'geography'. It will be treated as String.
I'm fine with "geography" being treated as "String", but the warning triggers warning mails every time a cronjob executes any rake task.
Any idea how I can silence this warning?
Thanks for your hints!
Looking at the source of ActiveRecord, I can answer the question myself:
The warning is hardcoded and therefore can't be silenced by AR configuration. However, RUBYOPT=-W0
gets rid of warnings altogether. This is a big chopper of course, but since I'm still getting those warnings in local development, I can live with a totally warning-less production system.
Update 2021:
After having updated the app to Rails 6.1, I got rid of this ugly hack and aliased the type properly in config/initializers/types.rb
:
# (other custom types here)
# This application uses the PostGIS extension without the corresponding postgis
# adapter gem and therefore the "geography" type is unknown to ActiveRecord which
# causes a warning:
#
# unknown OID: failed to recognize type of 'geography'. It will be treated as String.
#
# The following silences this warning by explicitly aliasing "geography" to "text".
module PostgresGeographyExtension
def load_additional_types(oids=nil)
type_map.alias_type 'geography', 'text'
super
end
end
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend PostgresGeographyExtension