diff options
author | CaselIT <cfederico87@gmail.com> | 2020-10-19 23:23:08 +0200 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-01-11 23:41:43 -0500 |
commit | 365283aac593698fa483b54554f9443db3fe4933 (patch) | |
tree | 08cfa15232ef2e63b444d506f5750a704f97901e /alembic/script | |
parent | ebc1ea35b127bd56c48dcae43d226471fd6bf6c0 (diff) | |
download | alembic-365283aac593698fa483b54554f9443db3fe4933.tar.gz |
Accommodate SQLAlchemy 1.4/2.0
To accommodate SQLAlchemy 1.4 and 2.0, the migration model now no longer
assumes that the SQLAlchemy Connection will autocommit an individual
operation. This essentially means that for databases that use
non-transactional DDL (pysqlite current driver behavior, MySQL), there is
still a BEGIN/COMMIT block that will surround each individual migration.
Databases that support transactional DDL should continue to have the
same flow, either per migration or per-entire run, depending on the
value of the :paramref:`.Environment.configure.transaction_per_migration`
flag.
Compatibility is established such that the entire library should
not generate any SQLAlchemy 2.0 deprecation warnings and
SQLALCHEMY_WARN_20 is part of conftest.py. (one warning remains
for the moment that needs to be resolved on the SQLAlchemy side)
The test suite requires SQLAlchemy 1.4.0b2 for testing 1.4;
1.4.0b1 won't work.
Test suite / setup also being modernized, as we are at
SQLAlchemy 1.3 we can now remove the majority of the testing
suite plugin.
Change-Id: If55b1ea3c12ead66405ab3fadc76d15d89dabb90
Diffstat (limited to 'alembic/script')
-rw-r--r-- | alembic/script/base.py | 12 | ||||
-rw-r--r-- | alembic/script/revision.py | 9 | ||||
-rw-r--r-- | alembic/script/write_hooks.py | 21 |
3 files changed, 24 insertions, 18 deletions
diff --git a/alembic/script/base.py b/alembic/script/base.py index fea9e87..363895c 100644 --- a/alembic/script/base.py +++ b/alembic/script/base.py @@ -171,7 +171,7 @@ class ScriptDirectory(object): "ancestor/descendant revisions along the same branch" ) ancestor = ancestor % {"start": start, "end": end} - compat.raise_from_cause(util.CommandError(ancestor)) + compat.raise_(util.CommandError(ancestor), from_=rna) except revision.MultipleHeads as mh: if not multiple_heads: multiple_heads = ( @@ -185,15 +185,15 @@ class ScriptDirectory(object): "head_arg": end or mh.argument, "heads": util.format_as_comma(mh.heads), } - compat.raise_from_cause(util.CommandError(multiple_heads)) + compat.raise_(util.CommandError(multiple_heads), from_=mh) except revision.ResolutionError as re: if resolution is None: resolution = "Can't locate revision identified by '%s'" % ( re.argument ) - compat.raise_from_cause(util.CommandError(resolution)) + compat.raise_(util.CommandError(resolution), from_=re) except revision.RevisionError as err: - compat.raise_from_cause(util.CommandError(err.args[0])) + compat.raise_(util.CommandError(err.args[0]), from_=err) def walk_revisions(self, base="base", head="heads"): """Iterate through all revisions. @@ -571,7 +571,7 @@ class ScriptDirectory(object): try: Script.verify_rev_id(revid) except revision.RevisionError as err: - compat.raise_from_cause(util.CommandError(err.args[0])) + compat.raise_(util.CommandError(err.args[0]), from_=err) with self._catch_revision_errors( multiple_heads=( @@ -659,7 +659,7 @@ class ScriptDirectory(object): try: script = Script._from_path(self, path) except revision.RevisionError as err: - compat.raise_from_cause(util.CommandError(err.args[0])) + compat.raise_(util.CommandError(err.args[0]), from_=err) if branch_labels and not script.branch_labels: raise util.CommandError( "Version %s specified branch_labels %s, however the " diff --git a/alembic/script/revision.py b/alembic/script/revision.py index 683d322..c75d1c0 100644 --- a/alembic/script/revision.py +++ b/alembic/script/revision.py @@ -422,9 +422,12 @@ class RevisionMap(object): except KeyError: try: nonbranch_rev = self._revision_for_ident(branch_label) - except ResolutionError: - raise ResolutionError( - "No such branch: '%s'" % branch_label, branch_label + except ResolutionError as re: + util.raise_( + ResolutionError( + "No such branch: '%s'" % branch_label, branch_label + ), + from_=re, ) else: return nonbranch_rev diff --git a/alembic/script/write_hooks.py b/alembic/script/write_hooks.py index 7d0843b..d6d1d38 100644 --- a/alembic/script/write_hooks.py +++ b/alembic/script/write_hooks.py @@ -39,9 +39,10 @@ def _invoke(name, revision, options): """ try: hook = _registry[name] - except KeyError: - compat.raise_from_cause( - util.CommandError("No formatter with name '%s' registered" % name) + except KeyError as ke: + compat.raise_( + util.CommandError("No formatter with name '%s' registered" % name), + from_=ke, ) else: return hook(revision, options) @@ -65,12 +66,13 @@ def _run_hooks(path, hook_config): opts["_hook_name"] = name try: type_ = opts["type"] - except KeyError: - compat.raise_from_cause( + except KeyError as ke: + compat.raise_( util.CommandError( "Key %s.type is required for post write hook %r" % (name, name) - ) + ), + from_=ke, ) else: util.status( @@ -89,12 +91,13 @@ def console_scripts(path, options): try: entrypoint_name = options["entrypoint"] - except KeyError: - compat.raise_from_cause( + except KeyError as ke: + compat.raise_( util.CommandError( "Key %s.entrypoint is required for post write hook %r" % (options["_hook_name"], options["_hook_name"]) - ) + ), + from_=ke, ) iter_ = pkg_resources.iter_entry_points("console_scripts", entrypoint_name) impl = next(iter_) |