"Database Transaction" functionality

Options

Hi,

How does this functionhttps://docs.xano.com/working-with-data/functions/database-requests/database-transaction work if a non-DB function fails?
If this happens:

  1. Edit record in user table
  2. Create a variable test equal to an empty object {}
  3. Create another variable equal to variable test.name, which fails because name isn't in test

Does step 1, Edit Record, get committed to the database?

Thank you!

Best Answer

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Answer ✓
    Options

    Hi @sepirak-nick if any function nested inside the database transaction fails, then all DB functions will NOT get committed. Everything needs to be successful for the DB functions to be committed.

Answers

  • sepirak-nick
    sepirak-nick Member
    Options

    Thank you, @Michael Udinski

    What if the DB edit function is in a nested function? For example, I had the following stack:
    1. Database Transaction
    1.1 Edit User
    1.1.1 Edit Record (DB transaction) ← Actually makes the DB update
    1.1.2 Return User record with addon ← DB Get record
    1.2 <Some statement that throws an error>

    Does the nested Edit Record function get committed?

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options

    No, the nested Edit Record function would not get committed in this case because it's still dependent on the "parent" DB transaction, which is throwing an error in 1.2