From 05758917329879da4b814e4786a9763d0c299432 Mon Sep 17 00:00:00 2001 From: woylie <13847569+woylie@users.noreply.github.com> Date: Sun, 9 Aug 2026 16:53:29 +0200 Subject: [PATCH] avoid compile-time dependency on modules named in derive --- lib/ecto/schema.ex | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/ecto/schema.ex b/lib/ecto/schema.ex index 7e52f245c5..f91a86c217 100644 --- a/lib/ecto/schema.ex +++ b/lib/ecto/schema.ex @@ -2390,10 +2390,12 @@ defmodule Ecto.Schema do on_writable_violation_default = Module.get_attribute(module, :on_writable_violation, :nothing) struct_fields = Module.get_attribute(module, :ecto_struct_fields) |> Enum.reverse() - derive = Module.get_attribute(module, :derive) - if redacted_fields != [] and not List.keymember?(derive, Inspect, 0) and - derive_inspect?(module) do + # Reading @derive makes every module named in its options a compile-time + # dependency of the schema. Keep the read last so it is skipped unless a + # redacted field actually requires deriving Inspect. + if redacted_fields != [] and derive_inspect?(module) and + not List.keymember?(Module.get_attribute(module, :derive), Inspect, 0) do Module.put_attribute(module, :derive, {Inspect, except: redacted_fields}) end