Wrong route pick up by Phoenix Routes.path

Hi, may I know why does my Routes.path pick up the wrong route?

I have only two routes for this entity

presentation_session_path  GET     /api/presentations/:presentation_id/sessions/:id  SentiWeb.SessionController :show
presentation_session_path  POST    /api/presentations/:presentation_id/sessions      SentiWeb.SessionController :create

In my session create method

  def create(conn, %{"session" => session_params}) do
    with {:ok, %Sessions{} = session} <- Questionnaire.create_session(session_params) do
      |> put_status(:created)
      |> put_resp_header("location", Routes.presentation_session_path(conn, :show, session))
      |> render("show.json", session: session)
      _ -> json(conn, %{Message: "Please enter the questions for the selected presentation!"})

In |> put_resp_header line, I expect the GET route path would be pick up but it wasn’t and instead its the POST method as per Dialyzer

Dialyzer warning:

positions 2nd from the success typing arguments:
(atom() | struct(), :create, any())
ElixirLS Dialyzer

Can someone enlighten me, why would Routes.presentation_session_path expects :create as expected argument instead of :show?

Can you share the relevant part of your routes? You mentioned that you defined two routes but only shared one with us.

Post updated. The other route wasn’t shown in the post.

You do not provide presentation_id, so it thinks session is presentation_id, and session_id is nil → post path.

1 Like