Errors & Linters#
pgdorm separates client-side build/lint errors from server-side PostgreSQL protocol errors, mapping PostgreSQL SQLSTATE codes directly onto typed Python exception classes in the Rust wire layer.
See Transactions, Locks & Queues for retry loops with RetryablePgError and OptimisticLockError, and Joins & Folios for JoinLintError.
Master SQLSTATE & Retryability Matrix#
| Exception | Base Class | PostgreSQL SQLSTATE(s) | Retryable? |
|---|---|---|---|
UniqueViolationError |
IntegrityError |
23505 |
No |
ForeignKeyViolationError |
IntegrityError |
23503 |
No |
NotNullViolationError |
IntegrityError |
23502 |
No |
CheckViolationError |
IntegrityError |
23514 |
No |
ExclusionViolationError |
IntegrityError |
23P01 |
No |
RestrictViolationError |
IntegrityError |
23001 |
No |
IntegrityError |
PostgresError |
23*** (other class 23) |
No |
RetryablePgError |
PostgresError |
40001 (serialization failure), 40P01 (deadlock detected) |
Yes (Pool.retry_transaction) |
LockNotAvailableError |
PostgresError |
55P03 |
Application-dependent |
QueryCanceledError |
PostgresError |
57014 |
Application-dependent |
ReadOnlyTransactionError |
PostgresError |
25006 |
No |
InsufficientPrivilegeError |
PostgresError |
42501 |
No |
AdminShutdownError |
PostgresError |
57P01, 57P02, 57P03 |
Reconnect / retry |
TooManyRequestsError |
PostgresError |
53300 (too many connections) |
Backoff & retry |
SubtransactionLimitError |
PostgresError |
Client/runtime savepoint guard (max_savepoints) |
No |
Client & Linter Errors#
PgdormError#
Base class for all client-side pgdorm exceptions (schema linting, query building, join linting, unsafe DML guards, result cardinality, and optimistic locking).
SchemaLintError#
Raised when a Table or TypeTable definition violates pgdorm schema invariants: explicit table name overrides, missing own-PK (<table_name>_id), TypeTable naming/code rules, duplicate physical tables/indexes/constraints across a schema set, or string discriminators. See Column Types & DDL.
JoinLintError#
Raised during Select.join(...) when a join is ambiguous (multiple FKs between tables without an explicit on=), violates require_using=True, or traverses an unindexed FK without .allow_seq_scan(reason=...). See Joins & Folios.
QueryBuildError#
Raised when a query or DML builder is misconfigured (e.g., invalid projection, mismatched set-op arity, invalid RETURNING target, or a feature requested against a server version that lacks it).
UnsafeDmlError#
Raised when compiling or executing an update(...) or delete(...) without a .where(...) clause unless .allow_full_table(reason=...) was explicitly declared. See Patch & Returning.
NoResultError#
Raised by Pool.one(...), Transaction.one(...), and Pool.json_one(...) when the query returns zero rows.
MultipleResultsError#
Raised by .one(...), .one_or_none(...), and .json_one(...) when the query returns more than one row.
OptimisticLockError#
Raised by Pool.update_versioned(...) (or Transaction.update_versioned(...)) when the row's xmin or version column no longer matches, indicating a concurrent modification. See Transactions, Locks & Queues.
PostgreSQL Wire & SQLSTATE Errors#
PostgresError#
Base exception for all errors returned by PostgreSQL over the v3 wire protocol. Exposes structured diagnostic fields (sqlstate, message, detail, hint, constraint, table, column) parsed from the ErrorResponse message.
IntegrityError#
Base class for PostgreSQL class 23 integrity constraint violations.
UniqueViolationError#
PostgreSQL SQLSTATE 23505 (unique_violation). Raised when an INSERT, UPDATE, or MERGE violates a unique index or primary key constraint.
ForeignKeyViolationError#
PostgreSQL SQLSTATE 23503 (foreign_key_violation). Raised when a referenced parent key does not exist or a referenced row cannot be deleted/updated.
NotNullViolationError#
PostgreSQL SQLSTATE 23502 (not_null_violation). Raised when a NOT NULL column receives NULL.
CheckViolationError#
PostgreSQL SQLSTATE 23514 (check_violation). Raised when a row fails a CHECK constraint.
ExclusionViolationError#
PostgreSQL SQLSTATE 23P01 (exclusion_violation). Raised when a row conflicts with an EXCLUDE constraint (such as TemporalPrimaryKey or TemporalUnique overlapping ranges). See Temporal Bookings.
RestrictViolationError#
PostgreSQL SQLSTATE 23001 (restrict_violation). Raised when a RESTRICT referential action prevents a delete or update.
RetryablePgError#
PostgreSQL SQLSTATE 40001 (serialization_failure) or 40P01 (deadlock_detected). Automatically caught and retried with exponential backoff by Pool.retry_transaction(...). See Transactions, Locks & Queues.
LockNotAvailableError#
PostgreSQL SQLSTATE 55P03 (lock_not_available). Raised when a FOR UPDATE NOWAIT or lock_timeout expires before acquiring a lock.
QueryCanceledError#
PostgreSQL SQLSTATE 57014 (query_canceled). Raised when a statement is canceled by statement_timeout, .timeout_ms(...), or pg_cancel_backend.
ReadOnlyTransactionError#
PostgreSQL SQLSTATE 25006 (read_only_sql_transaction). Raised when a write statement executes inside a READ ONLY transaction or against a read-only replica.
InsufficientPrivilegeError#
PostgreSQL SQLSTATE 42501 (insufficient_privilege). Raised when the connected role lacks privileges or fails an RLS policy check. See Multitenancy & RLS.
AdminShutdownError#
PostgreSQL SQLSTATE 57P01 (admin_shutdown), 57P02 (crash_shutdown), or 57P03 (cannot_connect_now). Indicates server shutdown or restart.
TooManyRequestsError#
PostgreSQL SQLSTATE 53300 (too_many_connections) or pool admission limit exhaustion (max_waiting).
SubtransactionLimitError#
Raised when a transaction exceeds max_savepoints (default 64), protecting PostgreSQL from subtransaction overflow (SubtransControlLock contention).