Skip to content

feat: accept per-query repo options in data layer context - #290

Merged
zachdaniel merged 5 commits into
ash-project:mainfrom
palermo-git:per-query-repo-opts
Dec 2, 2026
Merged

zachdaniel merged 5 commits into
ash-project:mainfrom
palermo-git:per-query-repo-opts

Conversation

@palermo-git

@palermo-git palermo-git commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Part of #286

AshSql.repo_opts/6 takes the query or changeset context and merges context.data_layer.repo_opts into the options it returns. It accepts :log, :telemetry_event and :telemetry_options, validated with Spark.Options; anything else raises Spark.Options.ValidationError. A nil value counts as no options. repo_opts can't override :prefix or :timeout, which keep their existing sources.

repo_opts/5 behaves as before. The grouped and lateral aggregate queries now pass their query context, so aggregates run through AshSql honor the options. That includes AshSqlite's grouped aggregates; AshSqlite's own reads and writes call repo_opts/5 and are unchanged.

The AshPostgres side, forwarding the options from reads, aggregates, creates, updates, destroys and the bulk actions, is on a branch and needs this released first. I'll open it once this is in.

Contributor checklist

Leave anything that you believe does not apply unchecked.

  • I accept the AI Policy, or AI was not used in the creation of this PR.
  • Bug fixes include regression tests
  • Chores
  • Documentation changes
  • Features include unit/acceptance tests
  • Refactoring
  • Update dependencies

Comment thread lib/ash_sql.ex Outdated
opts ->
with true <- Keyword.keyword?(opts),
{:ok, opts} <- Keyword.validate(opts, @repo_option_keys),
true <- Enum.all?(opts, &valid_repo_option?/1) do

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to validate them (does Ecto not already validate them?) then we should do so w/ Spark.Opts as we do in other places.

@palermo-git

Copy link
Copy Markdown
Contributor Author

Ah, yes. Good to know. Adding an ash conventions check to my review cycles.

@palermo-git

Copy link
Copy Markdown
Contributor Author

From what I gather Ecto doesn't, at least not per query. It only checks :log in the repo config. A bad per-query value blows up in the log callback after the query has already run, and DBConnection catches it and dumps the query and params into the error log. So I kept the validation and moved it to Spark.Options.

@zachdaniel

Copy link
Copy Markdown
Contributor

Looks like some merge conflicts.

# Conflicts:
#	lib/aggregate/lateral/query.ex
@palermo-git

Copy link
Copy Markdown
Contributor Author

Merged main in, should be clean now...

@zachdaniel
zachdaniel merged commit 0ff1b97 into ash-project:main Dec 2, 2026
@zachdaniel

Copy link
Copy Markdown
Contributor

🚀 Thank you for your contribution! 🚀

@palermo-git
palermo-git deleted the per-query-repo-opts branch December 3, 2026 12:14
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.

2 participants