with self._conn.lock: self._conn.wait( self._execute_gen(query, params, prepare=prepare, binary=binary) ) except e._NO_TRACEBACK as ex: > raise ex.with_traceback(None) E sqlalchemy.exc.OperationalError: (psycopg.errors.ObjectInUse) database "bulkmailer_test_8349aeb9" is being accessed by other users E DETAIL: There is 1 other session using the database. E [SQL: DROP DATABASE IF EXISTS "bulkmailer_test_8349aeb9"] E (Background on this error at: https://sqlalche.me/e/20/e3q8) /usr/local/lib/python3.11/site-packages/psycopg/cursor.py:97: OperationalError =================================== FAILURES =================================== _ TestMaterializeCampaign.test_invoice_numbers_unique_across_materialize_calls _ self = db_engine = Engine(postgresql+psycopg://mailer:***@localhost:5432/bulkmailer_test_8349aeb9) def test_invoice_numbers_unique_across_materialize_calls(self, db_engine): """Same campaign materialized twice (draft re-preview) — the collision set is per call, but DB uniqueness per campaign holds because rows are regenerated. Verified: two calls with the same recipient set produce distinct plans and both unique sets.""" from sqlalchemy.orm import Session with Session(db_engine, expire_on_commit=False) as db: f = _seed_fixture(db, n_recipients=8) recs = db.query(Recipient).filter_by(list_id=f["campaign"].recipient_list_id).all() res1 = _async_materialize(db_engine, f["campaign"], recs, preview=True) res2 = _async_materialize(db_engine, f["campaign"], recs, preview=True) invs1 = {r.generated_invoice_number for r in res1["rows"]} invs2 = {r.generated_invoice_number for r in res2["rows"]} > assert len(invs1) == 8 and len(invs2) == 8 E AssertionError: assert (5 == 8) E + where 5 = len({'INV-0UK3-H4S29-6YCZP8-5707', 'INV-24LJ-W8VYM-K8YYK7-1549', 'INV-7UQ9-U7DMH-E099PJ-8308', 'INV-V6TV-P8ZN6-0AQHHV-7787', 'INV-X1X6-YG90W-PGOBMA-0206'}) tests/test_campaign_engine.py:199: AssertionError =========================== short test summary info ============================ FAILED tests/test_campaign_engine.py::TestMaterializeCampaign::test_invoice_numbers_unique_across_materialize_calls ERROR tests/test_campaign_engine.py::TestMaterializeCampaign::test_invoice_numbers_unique_across_materialize_calls 1 failed, 1 passed, 1 error in 6.88s