Error when creating queries or dashboards after enabling PostGIS extension in PostgreSQL
Opened this issue · 1 comments
luiskhernandez commented
Hi, I'm working on a project that uses PostgreSQL with the PostGIS extension. After enabling this extension, I encounter an error whenever I try to create a query or dashboard, even for queries on tables that do not contain PostGIS data.
undefined method `match?' for nil:NilClass
/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-postgis-adapter-8.0.3/lib/active_record/connection_adapters/postgis/oid/spatial.rb:47:in `parse_sql_type'
/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-postgis-adapter-8.0.3/lib/active_record/connection_adapters/postgis_adapter.rb:87:in `block (2 levels) in initialize_type_map'
/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/motor-admin-0.4.26/lib/motor/active_record_utils/types.rb:60:in `block in build_types_hash'
/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/motor-admin-0.4.26/lib/motor/active_record_utils/types.rb:57:in `each'
/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/motor-admin-0.4.26/lib/motor/active_record_utils/types.rb:57:in `map'
/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/motor-admin-0.4.26/lib/motor/active_record_utils/types.rb:57:in `build_types_hash'
/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/motor-admin-0.4.26/lib/motor/active_record_utils/types.rb:34:in `block in all'
/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/motor-admin-0.4.26/lib/motor/active_record_utils/types.rb:33:in `synchronize'
/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/motor-admin-0.4.26/lib/motor/active_record_utils/types.rb:33:in `all'
/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/motor-admin-0.4.26/lib/motor/active_record_utils/types.rb:44:in `find_name_for_type'
/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/motor-admin-0.4.26/lib/motor/queries/run_query.rb:90:in `block in build_columns_hash'
/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/motor-admin-0.4.26/lib/motor/queries/run_query.rb:87:in `map'
/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/motor-admin-0.4.26/lib/motor/queries/run_query.rb:87:in `with_index'
/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/motor-admin-0.4.26/lib/motor/queries/run_query.rb:87:in `build_columns_hash'
/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/motor-admin-0.4.26/lib/motor/queries/run_query.rb:39:in `call!'
/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/motor-admin-0.4.26/lib/motor/queries/run_query.rb:47:in `call'
/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/motor-admin-0.4.26/app/controllers/motor/run_queries_controller.rb:23:in `render_result'
/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/motor-admin-0.4.26/app/controllers/motor/run_queries_controller.rb:17:in `create'
luiskhernandez commented
As a workaround I'm excluding those types
def build_types_hash
connection_class = defined?(::ResourceRecord) ? ::ResourceRecord : ActiveRecord::Base
type_map = connection_class.connection.send(:type_map)
array = type_map.instance_variable_get(:@mapping)
strings_to_filter = [
'geography',
'geometry',
'geometry_collection',
'line_string',
'multi_line_string',
'multi_point',
'multi_polygon',
'st_point',
'st_polygon'
]
filtered_array = array.reject { |string, _proc| strings_to_filter.include?(string) }
filtered_array.map do |name, type|
next unless name.is_a?(String)
[type.call.class.to_s, name]
end.compact.to_h
end
But not sure if they could be added here?
UNIFIED_TYPES = {
'smallint' => 'integer',
'int' => 'integer',
'int4' => 'integer',
'int8' => 'integer',
'int16' => 'integer',
'bigint' => 'integer',
'numeric' => 'float',
'decimal' => 'float',
'float4' => 'float',
'bpchar' => 'string',
'float8' => 'float',
'float16' => 'float',
'text' => 'string',
'citext' => 'string',
'jsonb' => 'json',
'bool' => 'boolean',
'timestamp' => 'datetime',
'timestamptz' => 'datetime'
}.freeze