-
-
Notifications
You must be signed in to change notification settings - Fork 300
Closed
Labels
awaiting infowaiting for the submitter to give more informationwaiting for the submitter to give more informationbugSomething isn't workingSomething isn't workingcant reproduce
Description
Describe the bug
Attempting to test downgrading of all revisions throws alembic.script.revision.RevisionError: Not a valid downgrade target from current heads.
Expected behavior
Downgrading should succeed.
To Reproduce
Please try to provide a Minimal, Complete, and Verifiable example, with the migration script and/or the SQLAlchemy tables or models involved.
See also Reporting Bugs on the website.
This test code which passes with alembic < 1.6.0 fails on 1.6.0 and 1.6.1
import unittest
import alembic.command
from mailman.database.alembic import alembic_cfg
class TestMigrations(unittest.TestCase):
layer = ConfigLayer
def setUp(self):
alembic.command.stamp(alembic_cfg, 'head')
def test_all_migrations(self):
script_dir = alembic.script.ScriptDirectory.from_config(alembic_cfg)
revisions = [sc.revision for sc in script_dir.walk_revisions()]
with catch_warnings():
simplefilter('ignore', UserWarning)
# Alembic/SQLite does not like something about these migrations.
# They're more or less inconsequential in practice (since users
# will rarely if ever downgrade their database), but it does
# clutter up the test output, so just suppress the warning.
#
# E.g.
# alembic/util/messaging.py:69: UserWarning:
# Skipping unsupported ALTER for creation of implicit constraint
for revision in revisions:
alembic.command.downgrade(alembic_cfg, revision)
revisions.reverse()
for revision in revisions:
alembic.command.upgrade(alembic_cfg, revision)The contents of mailman.database.alembic.init.py are:
from alembic.config import Config
from contextlib import ExitStack
from mailman.utilities.modules import expand_path
from public import public
with ExitStack() as resources:
cfg_path = expand_path(resources, 'python:mailman.config.alembic')
public(alembic_cfg=Config(cfg_path))Error
Traceback (most recent call last):
File "/var/MM/3/na/mailman/.tox/py37-nocov/lib/python3.7/site-packages/alembic/script/base.py", line 171, in _catch_revision_errors
yield
File "/var/MM/3/na/mailman/.tox/py37-nocov/lib/python3.7/site-packages/alembic/script/base.py", line 386, in _downgrade_revs
for script in revs
File "/var/MM/3/na/mailman/.tox/py37-nocov/lib/python3.7/site-packages/alembic/script/base.py", line 383, in <listcomp>
migration.MigrationStep.downgrade_from_script(
File "/var/MM/3/na/mailman/.tox/py37-nocov/lib/python3.7/site-packages/alembic/script/revision.py", line 711, in iterate_revisions
assert_relative_length=assert_relative_length,
File "/var/MM/3/na/mailman/.tox/py37-nocov/lib/python3.7/site-packages/alembic/script/revision.py", line 1212, in _collect_downgrade_revisions
"Not a valid downgrade target from current heads"
alembic.script.revision.RevisionError: Not a valid downgrade target from current heads
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/var/MM/3/na/mailman/src/mailman/database/tests/test_migrations.py", line 78, in test_all_migrations
alembic.command.downgrade(alembic_cfg, revision)
File "/var/MM/3/na/mailman/.tox/py37-nocov/lib/python3.7/site-packages/alembic/command.py", line 335, in downgrade
script.run_env()
File "/var/MM/3/na/mailman/.tox/py37-nocov/lib/python3.7/site-packages/alembic/script/base.py", line 490, in run_env
util.load_python_file(self.dir, "env.py")
File "/var/MM/3/na/mailman/.tox/py37-nocov/lib/python3.7/site-packages/alembic/util/pyfiles.py", line 97, in load_python_file
module = load_module_py(module_id, path)
File "/var/MM/3/na/mailman/.tox/py37-nocov/lib/python3.7/site-packages/alembic/util/compat.py", line 182, in load_module_py
spec.loader.exec_module(module)
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/var/MM/3/na/mailman/src/mailman/database/alembic/env.py", line 76, in <module>
run_migrations_online()
File "/var/MM/3/na/mailman/src/mailman/database/alembic/env.py", line 70, in run_migrations_online
context.run_migrations()
File "<string>", line 8, in run_migrations
File "/var/MM/3/na/mailman/.tox/py37-nocov/lib/python3.7/site-packages/alembic/runtime/environment.py", line 813, in run_migrations
self.get_context().run_migrations(**kw)
File "/var/MM/3/na/mailman/.tox/py37-nocov/lib/python3.7/site-packages/alembic/runtime/migration.py", line 549, in run_migrations
for step in self._migrations_fn(heads, self):
File "/var/MM/3/na/mailman/.tox/py37-nocov/lib/python3.7/site-packages/alembic/command.py", line 324, in downgrade
return script._downgrade_revs(revision, rev)
File "/var/MM/3/na/mailman/.tox/py37-nocov/lib/python3.7/site-packages/alembic/script/base.py", line 386, in _downgrade_revs
for script in revs
File "/usr/local/lib/python3.7/contextlib.py", line 130, in __exit__
self.gen.throw(type, value, traceback)
File "/var/MM/3/na/mailman/.tox/py37-nocov/lib/python3.7/site-packages/alembic/script/base.py", line 205, in _catch_revision_errors
compat.raise_(util.CommandError(err.args[0]), from_=err)
File "/var/MM/3/na/mailman/.tox/py37-nocov/lib/python3.7/site-packages/alembic/util/compat.py", line 294, in raise_
raise exception
alembic.util.exc.CommandError: Not a valid downgrade target from current heads
Versions.
- OS: Linux
- Python: 3.6 through 3.9
- Alembic: >= 1.6.0
- SQLAlchemy: 1.3.24
- Database: SQlite, MySQL and PostgreSQL
- DBAPI: sqlite, pymysql and psycopg2
Additional context
Have a nice day!
Metadata
Metadata
Assignees
Labels
awaiting infowaiting for the submitter to give more informationwaiting for the submitter to give more informationbugSomething isn't workingSomething isn't workingcant reproduce