From bf0e73f30018a423a9acc3d8e94cfa8ff299ed10 Mon Sep 17 00:00:00 2001 From: Iryoung Jeong Date: Thu, 15 Nov 2012 15:23:12 +0900 Subject: [PATCH] Updates clear_db() to unregister models and close session. fixes bug 1080988 This change fixes the bug by ensuring the metadata and session objects are properly cleaned up by clear_db(). Using the proper calls reduces the memory required by unit tests. Change-Id: I1d1802b642eff83b7f96211608195afaf68e855a --- quantum/db/api.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/quantum/db/api.py b/quantum/db/api.py index 4c0de4cdb..cd3163340 100644 --- a/quantum/db/api.py +++ b/quantum/db/api.py @@ -85,13 +85,15 @@ def configure_db(options): def clear_db(base=BASE): - global _ENGINE + global _ENGINE, _MAKER assert _ENGINE - for table in reversed(base.metadata.sorted_tables): - try: - _ENGINE.execute(table.delete()) - except Exception as e: - LOG.info("Unable to delete table. %s.", e) + + unregister_models(base) + if _MAKER: + _MAKER.close_all() + _MAKER = None + _ENGINE.dispose() + _ENGINE = None def get_session(autocommit=True, expire_on_commit=False): -- 2.45.2