Archive: #rootcause

2025-11-03

aka yesterday

â–Šī¸Ž Introducing Rootcause

Something that always made me wonder: why doesn't the IntegrityError raised by a database (driver) include some actual actionable data?

I don't know. I do know that it doesn't have to stay that way! With Rootcause you'll be able to gather all necessary information when you violate the most common types of constraints in Django.

import rootcause

try:
    ... # something violates a constraint
except IntegrityError as e:
    cause = rootcause.resolve(e, model=MyModel)
    if cause.is_check(name="max_amount"):
        raise MaxAmountExceeded()
    if cause.is_unique(name="payment_reference"):
        raise AlreadyPaid()

The goal of Rootcause is twofold: provide more information and eliminate differences between databases.

Rootcause has been tested with recent versions of SQLite, PostgreSQL and MySQL, and requires Django 5.1 or better.

Go check it out over on GitHub and fetch it from PyPI.