weixin_39890652 2020-11-30 11:37
浏览 0

EnvironmentContext.get_revision_arguments() and EnvironmentContext.get_head_revisions() returns incorrect values

Migrated issue, originally created by Dimitry Lukashov

When there are multiple active heads and the alembic_version table has multiple records Script.as_revision_number() should return a tuple, instead it returns only returns the hex identifier of one of the heads, making EnvironmentContext.get_head_revisions() useless and EnvironmentContext.get_revision_arguments() not very helpful when there are multiple heads.

Here is my proposed solution:


--- a/alembic/runtime/environment.py
+++ b/alembic/runtime/environment.py
@@ -201,8 +201,9 @@ class EnvironmentContext(util.ModuleClsProxy):
         ``upgrade`` or ``downgrade`` command.

         If it was specified as ``head``, the actual
-        version number is returned; if specified
-        as ``base``, ``None`` is returned.
+        version number is returned; if specified as
+        ``heads`` a tuple of version numbers is returned;
+        if specified as ``base``, ``None`` is returned.

         This function does not require that the :class:`.MigrationContext`
         has been configured.
diff --git a/alembic/script/base.py b/alembic/script/base.py
index 2e6e0fb..419fce8 100644
--- a/alembic/script/base.py
+++ b/alembic/script/base.py
@@ -228,7 +228,7 @@ class ScriptDirectory(object):
             return self.revision_map.get_revision(id_)

     def as_revision_number(self, id_):
-        """Convert a symbolic revision, i.e. 'head' or 'base', into
+        """Convert a symbolic revision, i.e. 'head', 'heads' or 'base', into
         an actual revision number."""

         with self._catch_revision_errors():
@@ -237,6 +237,9 @@ class ScriptDirectory(object):
         if not rev:
             # convert () to None
             return None
+        elif id_ == 'heads':
+            # expects a tuple
+            return rev
         else:
             return rev[0]


该提问来源于开源项目:sqlalchemy/alembic

  • 写回答

7条回答 默认 最新

  • weixin_39890652 2020-11-30 11:37
    关注

    Dimitry Lukashov wrote:

    PS I tried to submit a pull request and got a repository access denied. error.

    评论

报告相同问题?