From c0fbd149c4dc58488967eb2828a101ebaad1b5c8 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 27 Dec 2013 10:25:51 -0500 Subject: [PATCH] - Fixed bug in the not-internally-used :meth:`.ScriptDirectory.get_base` method which would fail if called on an empty versions directory. --- alembic/script.py | 2 +- docs/build/changelog.rst | 6 ++++++ tests/test_revision_create.py | 7 ++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/alembic/script.py b/alembic/script.py index cd28d7a1..34fd1500 100644 --- a/alembic/script.py +++ b/alembic/script.py @@ -297,7 +297,7 @@ class ScriptDirectory(object): """ for script in self._revision_map.values(): - if script.down_revision is None \ + if script and script.down_revision is None \ and script.revision in self._revision_map: return script.revision else: diff --git a/docs/build/changelog.rst b/docs/build/changelog.rst index a8488413..088018ef 100644 --- a/docs/build/changelog.rst +++ b/docs/build/changelog.rst @@ -6,6 +6,12 @@ Changelog .. changelog:: :version: 0.6.2 + .. change:: + :tags: bug + + Fixed bug in the not-internally-used :meth:`.ScriptDirectory.get_base` + method which would fail if called on an empty versions directory. + .. change:: :tags: bug :tickets: 157 diff --git a/tests/test_revision_create.py b/tests/test_revision_create.py index aa85809b..07ed6d44 100644 --- a/tests/test_revision_create.py +++ b/tests/test_revision_create.py @@ -24,9 +24,11 @@ class GeneralOrderedTests(unittest.TestCase): def_ = util.rev_id() ne_(abc, def_) - def test_003_heads(self): + def test_003_api_methods_clean(self): eq_(env.get_heads(), []) + eq_(env.get_base(), None) + def test_004_rev(self): script = env.generate_revision(abc, "this is a message", refresh=True) eq_(script.doc, "this is a message") @@ -36,6 +38,7 @@ class GeneralOrderedTests(unittest.TestCase): os.path.join(env.dir, 'versions', '%s_this_is_a_message.py' % abc), os.F_OK) assert callable(script.module.upgrade) eq_(env.get_heads(), [abc]) + eq_(env.get_base(), abc) def test_005_nextrev(self): script = env.generate_revision(def_, "this is the next rev", refresh=True) @@ -48,6 +51,7 @@ class GeneralOrderedTests(unittest.TestCase): assert callable(script.module.upgrade) assert callable(script.module.downgrade) eq_(env.get_heads(), [def_]) + eq_(env.get_base(), abc) def test_006_from_clean_env(self): # test the environment so far with a @@ -60,6 +64,7 @@ class GeneralOrderedTests(unittest.TestCase): eq_(abc_rev.revision, abc) eq_(def_rev.down_revision, abc) eq_(env.get_heads(), [def_]) + eq_(env.get_base(), abc) def test_007_no_refresh(self): rid = util.rev_id() -- 2.47.2