Render/4 deprecated warning in phx 1.4

I updated my app to phx 1.4 Every thing is working fine but when i run test cases. It gives me warning for almost every test case.

        warning: Elixir.Phoenix.Controller.render/4 with a view is deprecated, see the documentation for render/3 
          for an alternative
        (phoenix) lib/phoenix/controller.ex:719: Phoenix.Controller.render/4
        (app) web/router.ex:8: App.Router.token_auth/2
        (app) web/router.ex:1: App.Router.__pipe_through2__/1
        (phoenix) lib/phoenix/router.ex:270: Phoenix.Router.__call__/1
        (app) lib/app/endpoint.ex:1: App.Endpoint.plug_builder_call/2
        (app) lib/haitracker/endpoint.ex:1: App.Endpoint.call/2

I didn’t see any changelog regarding to the render function.

Any suggestions?

The docs referenced in that error do explain what to do:

This change is documented in the 1.4 changelog.

8 Likes

Thanks
I overlooked it.

1 Like

Your welcome. It can be a little overwhelming when you get a warning from almost every test :slight_smile:

1 Like

any idea to resolve the warning? I see 2 - 3 warnings in every test.

1 Like
     conn
      |> put_view(ViewModule)
      |> render("render_method", data: data)

Replace your render/4 with this.

1 Like
warning: Elixir.Phoenix.Controller.render/4 with a view is deprecated, see the documentation for render/3 for an alternative
  (phoenix 1.6.5) lib/phoenix/controller.ex:758: Phoenix.Controller.render/4

I’m getting same warnings and I checked my code I couldn’t find any functions with arity render/4 all render() functions with 3 arguments.

Sample code below:


  @spec create(Plug.Conn.t(), map) :: Plug.Conn.t()
  def create(conn, params) do
    current_user = conn.assigns[:current_user]

    with {:ok, %Asset{} = asset} <- Document.create_asset(current_user, params) do
      render(conn, :asset, asset: asset)
    end
  end

  @doc """
  Asset index.
  """
  swagger_path :index do
    get("/assets")
    summary("Asset index")
    description("API to get the list of all assets created so far under an organisation")

    parameter(:page, :query, :string, "Page number")

    response(200, "Ok", Schema.ref(:AssetsIndex))
    response(401, "Unauthorized", Schema.ref(:Error))
  end

  @spec index(Plug.Conn.t(), map) :: Plug.Conn.t()
  def index(conn, params) do
    current_user = conn.assigns[:current_user]

    with %{
           entries: assets,
           page_number: page_number,
           total_pages: total_pages,
           total_entries: total_entries
         } <- Document.asset_index(current_user, params) do
      render(conn, "index.json",
        assets: assets,
        page_number: page_number,
        total_pages: total_pages,
        total_entries: total_entries
      )
    end
  end

Note: project serving only JSON API’s and I’m upgrading from Phoenix 1.4.14 to 1.6.5
How can I fix these issues?
How to find out what triggers these warnings?

I found the problem where it was triggering, in the MyAppWeb.FallbackController Module then I added the below code to MyAppWeb.FallbackController

conn
      |> put_view(ModuleView)
      |> render("render_method", data: data)

then added phoenix_view library to deps() in mix.exs

I’m just updating for future reference for the same problem, if anybody comes across

1 Like