mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
aurweb.testing.setup_test_db: Expunge objects
This is needed to avoid redundant objects in SQLAlchemy's IdentityMap, since we pass a direct .execute to delete the tables passed in. Additionally, remove our engine.connect() call in favor of relying on the already-established Session. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
b692b11f62
commit
794868b20f
1 changed files with 6 additions and 4 deletions
|
@ -21,10 +21,12 @@ def setup_test_db(*args):
|
|||
test_tables = ["Users", "Sessions"];
|
||||
setup_test_db(*test_tables)
|
||||
"""
|
||||
engine = aurweb.db.get_engine()
|
||||
conn = engine.connect()
|
||||
# Make sure that we've grabbed the engine before using the session.
|
||||
aurweb.db.get_engine()
|
||||
|
||||
tables = list(args)
|
||||
for table in tables:
|
||||
conn.execute(f"DELETE FROM {table}")
|
||||
conn.close()
|
||||
aurweb.db.session.execute(f"DELETE FROM {table}")
|
||||
|
||||
# Expunge all objects from SQLAlchemy's IdentityMap.
|
||||
aurweb.db.session.expunge_all()
|
||||
|
|
Loading…
Add table
Reference in a new issue