Skip to content

Narrow compile_env to leaf keys in :persistence and :cache#209

Open
rranelli wants to merge 1 commit into
tompave:masterfrom
rranelli:narrow-compile-env-to-leaf-keys
Open

Narrow compile_env to leaf keys in :persistence and :cache#209
rranelli wants to merge 1 commit into
tompave:masterfrom
rranelli:narrow-compile-env-to-leaf-keys

Conversation

@rranelli
Copy link
Copy Markdown

Application.compile_env/3 was previously called on the entire :persistence and :cache keyword lists, which caused every key inside those lists to be tracked at compile time — including keys that the library only ever reads at runtime (:repo, :adapter, :ttl). Any host application that legitimately overrode those keys in runtime.exs would trip Elixir's release-boot validate_compile_env check and abort.

Only three leaves are actually consumed at compile time:

  • :persistence.ecto_table_name — interpolated into schema(...) in FunWithFlags.Store.Persistent.Ecto.Record.
  • :persistence.ecto_primary_key_type — used in the @primary_key attribute in the same module.
  • :cache.enabled — used by store_module_determined_at_compile_time/0 to pick between FunWithFlags.Store and FunWithFlags.SimpleStore.

This change uses path-style Application.compile_env/3 to track only those leaves. All other keys in :persistence and :cache are once again free to be overridden at runtime without causing a boot failure, restoring the v1.6.0 intent of not compiling in the Ecto repo while keeping the v1.9.0 safety check for the keys that actually need it.

`Application.compile_env/3` was previously called on the entire
`:persistence` and `:cache` keyword lists, which caused every key inside
those lists to be tracked at compile time — including keys that the library
only ever reads at runtime (`:repo`, `:adapter`, `:ttl`). Any host
application that legitimately overrode those keys in `runtime.exs` would
trip Elixir's release-boot `validate_compile_env` check and abort.

Only three leaves are actually consumed at compile time:

* `:persistence.ecto_table_name` — interpolated into `schema(...)` in
  `FunWithFlags.Store.Persistent.Ecto.Record`.
* `:persistence.ecto_primary_key_type` — used in the `@primary_key`
  attribute in the same module.
* `:cache.enabled` — used by `store_module_determined_at_compile_time/0`
  to pick between `FunWithFlags.Store` and `FunWithFlags.SimpleStore`.

This change uses path-style `Application.compile_env/3` to track only
those leaves. All other keys in `:persistence` and `:cache` are once
again free to be overridden at runtime without causing a boot failure,
restoring the v1.6.0 intent of not compiling in the Ecto repo while
keeping the v1.9.0 safety check for the keys that actually need it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant