When running a multi in Repo.transaction, I dont get error or ok back

I have a multi exactly below

  names: #MapSet<[:record_0]>,
  operations: [
    record_0: {:changeset,
       action: :insert,
       changes: %{
         app_version: "0.7.0",
         card_id: "37faf84a-afdd-48b5-a9bd-20b789790153",
         merchant_device_id: "71aefe98-dfa8-4ba3-97ed-20419fab44f5",
         merchant_device_transaction_number: 0,
         merchant_player_id: "8ea9abcd-0c26-450d-b1d8-ed0f364b8355",
         purchase_amount: #Decimal<88.0>,
         purchase_metric_id: "3b7f242c-8831-4066-a91c-928d77764bb9",
         transaction_id: "a49cca05-e090-42ba-bb85-bae58ea4d055"
       errors: [],
       data: #Pogio.V1.TransactionPurchase<>,
       valid?: true
     >, []}

But when I run


Boom nothing happens, no crash, no log. and I got back nothing. infact control is not returned and 500 response is sent back to user.

Elixir version (elixir -v):
Elixir 1.10.2 (compiled with Erlang/OTP 21)
Erlang/OTP version (erl):
Erlang/OTP 21
Operating system:
Erlang/OTP 21
Is this an umbrella application?:
Release type (Distillery, mix release, Mix, etc.):
iex -S mix phx.server

its working perfectly fine in some cases but not in one case. Any help or workaround or help in debugging is really appreciated

data is successfully inserted. I can see in the logs

That likely indicates that something failed to handle an error in your code; are there any indexes / constraints that would be violated by that insert statement?

Even if there are constraints or failures, it should have crashed or given some errors back(should have given back control). below is the code which I use just to confirm if after statement ever got printed(but it doesnt)

IO.inspect("its printing.....")
response =  Data.Repo.transaction(multi)
IO.inspect("never got printed")

Repo.transaction will raise on a constraint failure, unless the corresponding check_constraint or similar function is used to tell the changeset how to handle the situation.

If your code doesn’t rescue the exception, Phoenix will, and then call the fallback controller.

1 Like

Issue was solved by using try/rescue. Thanks