Skip to content

Created a flag for disabling ash_paper_trail#228

Merged
zachdaniel merged 3 commits intoash-project:mainfrom
dallingson:main
Feb 13, 2026
Merged

Created a flag for disabling ash_paper_trail#228
zachdaniel merged 3 commits intoash-project:mainfrom
dallingson:main

Conversation

@dallingson
Copy link
Copy Markdown
Contributor

Add runtime flag to disable paper trail versioning per action

What

Adds a context flag ash_paper_trail_disabled? so you can skip creating versions for specific actions.

Why

There was no way to turn off versioning for migrations, imports, or other operations where you don't want audit history.

How to use

Option 1 – when calling the action:

Post.update!(post, attrs, context: %{ash_paper_trail_disabled?: true})

Option 2 – on the action definition:

update :my_action do
  change set_context(%{ash_paper_trail_disabled?: true})
end

Changes

  • create_new_version.ex – Check the flag in valid_for_tracking? and run that check after all changes so both call-site and action-level usage work.
  • Docs – New "Disabling Versioning at Runtime" section.
  • Tests – Tests for create, update, destroy, bulk, and action-level usage.
  • Refactor – Extracted shared logic into should_record_version_for_action?/2 and version_context/1 to remove duplication.

Contributor checklist

Leave anything that you believe does not apply unchecked.

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

of versioning for a specific action at runtime
else
changeset
end
create_new_version(changeset)
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.

We should leave this logic here. We can add an additional check inside of the after_action callback.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, I will go in and make these changes and commit them soon

the flag to the after_action callback so that it
works for both the action and the call site.

@impl true
def change(changeset, _, _) do
create_new_version(changeset)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Here are the changes... did I get this right? Let me know if there is anything else I need to change.

defp create_new_version(changeset) do
Ash.Changeset.after_action(changeset, fn changeset, result ->
changed? = changed?(changeset, result)
unless changeset.context[:ash_paper_trail_disabled?] 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.

Lets switch to if, because unless is deprecated in newer elixir versions. Otherwise this looks great!

@zachdaniel zachdaniel merged commit 6d1b54b into ash-project:main Feb 13, 2026
22 of 23 checks passed
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