Skip to content

Commit

Permalink
Updates clear_db() to unregister models and close session.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
iryoung authored and Gary Kotton committed Nov 16, 2012
1 parent 925b418 commit bf0e73f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions quantum/db/api.py
Expand Up @@ -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):
Expand Down

0 comments on commit bf0e73f

Please sign in to comment.