Skip to content

Commit

Permalink
Improve attachment support detection (#567)
Browse files Browse the repository at this point in the history
This fixes a subtle bug which we encountered on one project in tests.

The problem is that `function_exported?` returns false if the module is not loaded (see [here](https://hexdocs.pm/elixir/Kernel.html?#function_exported?/3)). Consequently, if the beam is started in interactive mode (default when mix is used), Bamboo may incorrectly conclude that attachments are not supported.

This can lead to some strange behaviour in tests. For example, we had a test failing if executed in isolation, but sometimes the test would pass if all the tests are running. The test would always pass if the test adapter is recompiled while invoking `mix test`.

Note that the same issue can occur in prod if OTP release is not used.
  • Loading branch information
sasa1977 authored Dec 1, 2020
1 parent 2137164 commit 4626eea
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/bamboo/mailer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ defmodule Bamboo.Mailer do
defp validate_attachment_support(%{attachments: []} = email, _adapter), do: email

defp validate_attachment_support(email, adapter) do
if function_exported?(adapter, :supports_attachments?, 0) && adapter.supports_attachments? do
if Code.ensure_loaded?(adapter) && function_exported?(adapter, :supports_attachments?, 0) &&
adapter.supports_attachments? do
email
else
raise "the #{adapter} does not support attachments yet."
Expand Down

0 comments on commit 4626eea

Please sign in to comment.