From: Ash Berlin-Taylor Date: Fri, 21 Jun 2019 12:53:11 +0000 (-0400) Subject: Report warnings from caller's file/line number, not utils.py X-Git-Tag: rel_1_0_11~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=26453a8b284743bd590a86208968ca862caa67ca;p=thirdparty%2Fsqlalchemy%2Falembic.git Report warnings from caller's file/line number, not utils.py Warnings emitted by Alembic now include a default stack level of 2, and in some cases it's set to 3, in order to help warnings indicate more closely where they are originating from. Pull request courtesy Ash Berlin-Taylor. Closes: #578 Pull-request: https://github.com/sqlalchemy/alembic/pull/578 Pull-request-sha: 49d2922dc61bfc6da42a5f45b53f04032970daeb Change-Id: I31e19cacd63a4a7ff0557d9e7f52d348f63744d6 --- diff --git a/alembic/command.py b/alembic/command.py index f8c81cc1..3faafddf 100644 --- a/alembic/command.py +++ b/alembic/command.py @@ -476,7 +476,7 @@ def current(config, verbose=False, head_only=False): script = ScriptDirectory.from_config(config) if head_only: - util.warn("--head-only is deprecated") + util.warn("--head-only is deprecated", stacklevel=3) def display_version(rev, context): if verbose: diff --git a/alembic/ddl/impl.py b/alembic/ddl/impl.py index 5df7c040..0843ebf1 100644 --- a/alembic/ddl/impl.py +++ b/alembic/ddl/impl.py @@ -156,7 +156,8 @@ class DefaultImpl(with_metaclass(ImplMeta)): if autoincrement is not None or existing_autoincrement is not None: util.warn( "autoincrement and existing_autoincrement " - "only make sense for MySQL" + "only make sense for MySQL", + stacklevel=3, ) if nullable is not None: self._exec( diff --git a/alembic/runtime/migration.py b/alembic/runtime/migration.py index a4ad7408..b3a98633 100644 --- a/alembic/runtime/migration.py +++ b/alembic/runtime/migration.py @@ -175,7 +175,8 @@ class MigrationContext(object): util.warn( "'connection' argument to configure() is expected " "to be a sqlalchemy.engine.Connection instance, " - "got %r" % connection + "got %r" % connection, + stacklevel=3 ) dialect = connection.dialect elif url: diff --git a/alembic/util/messaging.py b/alembic/util/messaging.py index 1e72c195..6a30133e 100644 --- a/alembic/util/messaging.py +++ b/alembic/util/messaging.py @@ -69,8 +69,8 @@ def obfuscate_url_pw(u): return str(u) -def warn(msg): - warnings.warn(msg) +def warn(msg, stacklevel=2): + warnings.warn(msg, stacklevel=stacklevel) def msg(msg, newline=True): diff --git a/docs/build/unreleased/warn_depth.rst b/docs/build/unreleased/warn_depth.rst new file mode 100644 index 00000000..0d82c9d4 --- /dev/null +++ b/docs/build/unreleased/warn_depth.rst @@ -0,0 +1,7 @@ +.. change:: + :tags: bug, environment + + Warnings emitted by Alembic now include a default stack level of 2, and in + some cases it's set to 3, in order to help warnings indicate more closely + where they are originating from. Pull request courtesy Ash Berlin-Taylor. +