ash-project / ash_json_api

The JSON:API extension for the Ash Framework
https://hexdocs.pm/ash_json_api
MIT License
56 stars 40 forks source link

JSON-API Related() Seems Broken #85

Closed ulbrich closed 1 year ago

ulbrich commented 1 year ago

Hi, 👋 there seems to be a regression in the JSON-API: It worked nicely (after you did a fix a couple of weeks ago), but after updating packages to the newest ones, I get an exception.

Here’s the relation:

related(:events, :events_by_extid) do
  route("/:extid/events")
end

This is the exception I get:

[error] #PID<0.3383.0> running TickerWeb.Endpoint (connection #PID<0.3382.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: GET /api/eventhub/alarms/R%201.5%20230310%201956/events
** (exit) an exception was raised:
    ** (UndefinedFunctionError) function :events.name/0 is undefined (module :events is not available)
        :events.name()
        (ash_json_api 0.32.0) lib/ash_json_api/controllers/helpers.ex:348: anonymous fn/1 in AshJsonApi.Controllers.Helpers.fetch_related/2
        (ash_json_api 0.32.0) lib/ash_json_api/controllers/get_related.ex:20: AshJsonApi.Controllers.GetRelated.call/2
        (ticker 0.1.0) deps/plug/lib/plug/router.ex:246: anonymous fn/4 in TickerWeb.Api.Router.dispatch/2
        [...]
        (cowboy 2.10.0) deps/cowboy/src/cowboy_handler.erl:37: :cowboy_handler.execute/2
        (cowboy 2.10.0) deps/cowboy/src/cowboy_stream_h.erl:306: :cowboy_stream_h.execute/3
        (cowboy 2.10.0) deps/cowboy/src/cowboy_stream_h.erl:295: :cowboy_stream_h.request_process/3
        (stdlib 4.3.1.1) proc_lib.erl:240: :proc_lib.init_p_do_apply/3

Here are the packages I’m using (I tried it with the newest release of ash_json_api as well as the head):

defp deps do
  [
    {:absinthe_plug, "~> 1.5.8"},
    {:ash, "~> 2.10.2"},
    {:ash_authentication, "~> 3.11.6"},
    {:ash_graphql, "~> 0.25.10"},
    # {:ash_json_api, "~> 0.32.0"},
    {:ash_json_api, git: "https://github.com/ash-project/ash_json_api.git", build: "main"},
    {:ash_postgres, "~> 1.3.30"},
    {:cors_plug, "~> 3.0.3"},
    {:elixir_sense, ">= 1.0.0", only: [:dev, :test]},
    {:ecto_sql, "~> 3.10.1"},
    {:ecto_sqlite3, ">= 0.10.3"},
    {:ex_phone_number, "== 0.3.0"},
    {:guardian, "~> 2.3.1"},
    {:haversine, "~> 0.1.0"},
    {:jason, "~> 1.2"},
    {:jose, "~> 1.11"},
    {:open_api_spex, "~> 3.17.3"},
    {:picosat_elixir, "~> 0.2.3"},
    {:phoenix, "~> 1.6.16"},
    {:phoenix_ecto, "~> 4.4.2"},
    {:phoenix_html, "~> 3.3.1"},
    {:plug_cowboy, "~> 2.6.1"},
    {:postgrex, "~> 0.16.5"},
    {:telemetry_metrics, "~> 0.6"},
    {:telemetry_poller, "~> 1.0"},
    {:tesla, "~> 1.6.0"}
  ]
end

Thanks for having a look! ❤️

zachdaniel commented 1 year ago

This should be fixed in main, if you don't mind trying main out that would be great :)

ulbrich commented 1 year ago

Sorry, but that didn't help: The error message is the same (and just to be sure I deleted _build, deleted deps/ash_json_api, did a mix clean && mix deps.get and it still remains…

[error] #PID<0.518.0> running TickerWeb.Endpoint (connection #PID<0.517.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: GET /api/eventhub/alarms/R%201.5%20230310%201956/events
** (exit) an exception was raised:
    ** (UndefinedFunctionError) function :events.name/0 is undefined (module :events is not available)
        :events.name()
        (ash_json_api 0.32.0) lib/ash_json_api/controllers/helpers.ex:348: anonymous fn/1 in AshJsonApi.Controllers.Helpers.fetch_related/2
        (ash_json_api 0.32.0) lib/ash_json_api/controllers/get_related.ex:20: AshJsonApi.Controllers.GetRelated.call/2
        (ticker 0.1.0) deps/plug/lib/plug/router.ex:246: anonymous fn/4 in TickerWeb.Api.Router.dispatch/2
        (telemetry 1.2.1) /Users/ulbrich/src/bwb/api/deps/telemetry/src/telemetry.erl:321: :telemetry.span/3
        (ticker 0.1.0) deps/plug/lib/plug/router.ex:242: TickerWeb.Api.Router.dispatch/2
        (ticker 0.1.0) lib/ticker_web/api/router.ex:1: TickerWeb.Api.Router.plug_builder_call/2
        (phoenix 1.6.16) lib/phoenix/router/route.ex:41: Phoenix.Router.Route.call/2
        (phoenix 1.6.16) lib/phoenix/router.ex:354: Phoenix.Router.__call__/2
        (ticker 0.1.0) lib/ticker_web/endpoint.ex:1: TickerWeb.Endpoint.plug_builder_call/2
        (ticker 0.1.0) deps/plug/lib/plug/debugger.ex:136: TickerWeb.Endpoint."call (overridable 3)"/2
        (ticker 0.1.0) lib/ticker_web/endpoint.ex:1: TickerWeb.Endpoint.call/2
        (phoenix 1.6.16) lib/phoenix/endpoint/cowboy2_handler.ex:54: Phoenix.Endpoint.Cowboy2Handler.init/4
        (cowboy 2.10.0) /Users/ulbrich/src/bwb/api/deps/cowboy/src/cowboy_handler.erl:37: :cowboy_handler.execute/2
        (cowboy 2.10.0) /Users/ulbrich/src/bwb/api/deps/cowboy/src/cowboy_stream_h.erl:306: :cowboy_stream_h.execute/3
        (cowboy 2.10.0) /Users/ulbrich/src/bwb/api/deps/cowboy/src/cowboy_stream_h.erl:295: :cowboy_stream_h.request_process/3
        (stdlib 4.3.1.1) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
zachdaniel commented 1 year ago

Did you do mix deps.update ash_json_api ?

ulbrich commented 1 year ago

Thanks for the hint: AFK for a couple of hours… 😇

ulbrich commented 1 year ago

Argh, that’s it! 🎉 So the wrench would have been better than the hammer… 🙂 Thanks and have a nice day/evening/whatever! 👋