Skip to content

Commit b3638a7

Browse files
committed
Cleanup
1 parent ba0c67c commit b3638a7

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

lib/ecto/schema.ex

+4-11
Original file line numberDiff line numberDiff line change
@@ -2326,16 +2326,10 @@ defmodule Ecto.Schema do
23262326

23272327
struct_fields = Module.get_attribute(module, :ecto_struct_fields) |> Enum.reverse()
23282328
derive = Module.get_attribute(module, :derive)
2329-
redact = Module.get_attribute(module, :redact)
2329+
already_derives_inspect? = List.keymember?(derive, Inspect, 0)
23302330

2331-
cond do
2332-
redact == :all_except_primary_keys ->
2333-
Module.put_attribute(module, :derive, {Inspect, only: primary_key_fields})
2334-
2335-
redacted_fields != [] and not List.keymember?(derive, Inspect, 0) and derive_inspect?(module) ->
2336-
Module.put_attribute(module, :derive, {Inspect, except: redacted_fields})
2337-
2338-
true -> :ok
2331+
if redacted_fields != [] and not already_derives_inspect? and derive_inspect_redacted?(module) do
2332+
Module.put_attribute(module, :derive, {Inspect, except: redacted_fields})
23392333
end
23402334

23412335
loaded =
@@ -2412,7 +2406,6 @@ defmodule Ecto.Schema do
24122406
{[:embeds], embed_names},
24132407
{[:updatable_fields], updatable},
24142408
{[:insertable_fields], insertable},
2415-
{[:redact_schema], redact},
24162409
{[:redact_fields], redacted_fields},
24172410
{[:autogenerate_fields], Enum.flat_map(autogenerate, &elem(&1, 0))},
24182411
{[:virtual_fields], Enum.map(virtual_fields, &elem(&1, 0))},
@@ -2449,7 +2442,7 @@ defmodule Ecto.Schema do
24492442
{struct_fields, bags_of_clauses}
24502443
end
24512444

2452-
defp derive_inspect?(module) do
2445+
defp derive_inspect_redacted?(module) do
24532446
case Module.get_attribute(module, :ecto_derive_inspect_for_redacted_fields) do
24542447
false ->
24552448
IO.warn(

0 commit comments

Comments
 (0)