Skip to content

Accept :ok as successful return for Repo.transact/2 fun - #4679

Closed
nirev wants to merge 1 commit into
elixir-ecto:masterfrom
nirev:transact-ok
Closed

nirev wants to merge 1 commit into
elixir-ecto:masterfrom
nirev:transact-ok

Conversation

@nirev

@nirev nirev commented Nov 11, 2025

Copy link
Copy Markdown
Contributor

This PR adds :ok as an accepted result for the fun passed to Repo.transact/2.

It is sometimes useful to return just :ok when you don't care about the results of the function, just that the sequence of operations executed successfully.

Eg:

def do_something do
  Repo.transact(fn -> 
    {:ok, x} = get_x_with_lock()
    {:ok, _} = update_all_records(x)
    
     :ok
  end)
end

@warmwaffles

Copy link
Copy Markdown
Member

In practice I've had to do {:ok, :ok} to achieve this or just return something. Typically though I've thought of it as forcing you to think about the side effect that is being caused and having to conciously return the meaningful mutation.

@nirev nirev closed this Nov 11, 2025
@nirev

nirev commented Nov 11, 2025

Copy link
Copy Markdown
Contributor Author

Closed this as I realized this would implicate in way more changes than it was worth 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.

2 participants