QamoosTech
DatabasesTransactionsIntermediateSQLDjango

Autocommit

PronunciationAW-toh-kuh-MIT

Definition

In autocommit mode every SQL statement is committed as soon as it finishes, as its own tiny transaction, unless you explicitly start a transaction.

Where you hear it

In database client settings, Django's default behaviour and bugs where half of a multi-step change was saved.

Examples

  • With autocommit on, the first insert is saved even if the second fails.
  • Wrap related writes in atomic() so they succeed or fail together.
  • Each insert commits by itself, so turning autocommit off made the import all-or-nothing.

Common mistake

Running several related writes in autocommit mode. A crash in the middle leaves the data half-updated.

Don't confuse with

An explicit transaction, where nothing is saved until you commit.

Say it at work

  • In a meeting or chatIs autocommit on in this session?
  • In an email or ticketStart a transaction first.