Error Geo.PostGIS.Types.find/2 is undefined (module Geo.PostGIS.Types is not available)

My current relevent versions:

      {:ecto, "3.13.0"},

      {:ecto_sql, "\~> 3.10"},

      {:postgrex, ">= 0.0.0"},

      {:geo, "\~> 4.0.0"},

      {:geo_postgis, "\~>  3.7.1"},

Already defined custom types:

Postgrex.Types.define(
  MyApp.PostgresTypes,
  [Geo.PostGIS.Extension] ++ Ecto.Adapters.Postgres.extensions(),
json: Jason)

Setup on the Repo Config:

  # Configure your local dev database
config :my_app, MyApp.Repo,
  username: "postgres",
  password: "password",
  hostname: "localhost",
  database: "dev",
  stacktrace: true,
  show_sensitive_data_on_connection_error: true,
  pool_size: 10,
  adapter: Ecto.Adapters.Postgres,
  types: MyApp.PostgresTypes

I keep getting this error:


 GenServer {Postgrex.TypeManager, {Geo.PostGIS.Types, {~c"localhost", 5432, "dev"}}} terminating
** (UndefinedFunctionError) function Geo.PostGIS.Types.find/2 is undefined (module Geo.PostGIS.Types is not available)

Only workaround has been to use raw SQL.

Does the atom Geo.PostGIS.Types appear anywhere in your application? Looking at the source of geo-postgis doesn’t turn up any references…

1 Like

The issue was the setup. I was reading outdated docs it seems.

In a postgres_types.ex file I had:

Postgrex.Types.define(
  MyApp.PostgresTypes,
  [Geo.PostGIS.Extension] ++ Ecto.Adapters.Postgres.extensions(),
  json: Jason
)

and in my repo.ex file I originally had:


defmodule MyApp.Repo do
  use Ecto.Repo,
    otp_app: :my_app,
    adapter: Ecto.Adapters.Postgres,
    types: MyApp.PostgresTypes

end

But that was not registering the module correctly.
Trying a bunch of random solutions, I eventually found this to work.

SOLUTION:

defmodule MyApp.Repo do
  use Ecto.Repo,
    otp_app: :MyApp,
    adapter: Ecto.Adapters.Postgres
   # Removed the types: ..  part that was here.

  @impl true

  def init(_type, config) do
    {:ok, Keyword.put(config, :types, MyApp.PostgresTypes)}
  end
  # ^ Adding this fixed it.

end

The main issue was the docs for post_gis only describe how to setup outside of Phoenix. i.e. They don’t detail how to setup the Repo when the Repo is initialised via this method.