diff --git a/umbratrans_web/tests/test_postgres_repository.py b/umbratrans_web/tests/test_postgres_repository.py index bfa2d23..63e2a2e 100644 --- a/umbratrans_web/tests/test_postgres_repository.py +++ b/umbratrans_web/tests/test_postgres_repository.py @@ -820,6 +820,12 @@ def _drop_tenant_schemas(dsn: str) -> None: schemas themselves would survive, and a hundred runs would leave a hundred schemas for organizations that no longer exist. Only reached when the guard above established the database held nothing to begin with. + + One schema per transaction, and that is load-bearing rather than tidy. Dropping + several hundred schemas in a single transaction exhausts the lock table and + fails with "out of shared memory ... max_locks_per_transaction" - a message + that reads like a PostgreSQL defect and is not one. It is the same constraint + the 0005 rollback documents, learned here first. """ pool = ConnectionPool(dsn, min_size=1, max_size=2, open=True, kwargs={"row_factory": dict_row}) @@ -830,6 +836,7 @@ def _drop_tenant_schemas(dsn: str) -> None: ).fetchall() for schema in schemas: connection.execute(f'DROP SCHEMA IF EXISTS "{schema["nspname"]}" CASCADE') + connection.commit() finally: pool.close()