tesla icon indicating copy to clipboard operation
tesla copied to clipboard

Tesla.Multipart.assert_part_value! doesn't allow valid stream

Open ananthakumaran opened this issue 1 year ago • 3 comments

  @spec assert_part_value!(any) :: :ok | no_return
  defp assert_part_value!(%maybe_stream{})
       when maybe_stream in [IO.Stream, File.Stream, Stream],
       do: :ok

The assert_part_value! function checks if the argument is a stream, but it only allows a subset of the valid streams. There is no restriction on what data type could be used to represent a stream

iex(1)> enum = 1001..9999
iex(2)> n = 3
iex(3)> stream = Stream.transform(1001..9999, 0, fn i, acc ->
...(3)>   if acc < n, do: {[i], acc + 1}, else: {:halt, acc}
...(3)> end)
#Function<60.29975488/2 in Stream.transform/3>

In the example above, stream is represented via a function. https://elixirforum.com/t/how-to-check-if-an-argument-is-a-stream-or-stream-like-function/50622

ananthakumaran avatar May 31 '24 17:05 ananthakumaran

@teamon focusing on other stuff right now, I haven't touch anything related to streaming, any thoughts here?

yordis avatar Oct 25 '24 02:10 yordis

I see two options here: allow functions in assert_part_value or... remove the validation. We probably should do the former first.

teamon avatar Oct 25 '24 06:10 teamon

Are you able to pick this one up? Trying to focus in other parts right now

yordis avatar Oct 25 '24 15:10 yordis