]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Report warnings from caller's file/line number 578/head
authorAsh Berlin-Taylor <ash_github@firemirror.com>
Fri, 21 Jun 2019 10:03:53 +0000 (11:03 +0100)
committerAsh Berlin-Taylor <ash_github@firemirror.com>
Fri, 21 Jun 2019 10:03:53 +0000 (11:03 +0100)
Seeing the warning come from `alembic/util/messaging.py:69` is not very
useful for tacking down the source of the incorrect call.

By default utils.warning will now report the warning from the caller,
but some cases it makes sense to report from the context of the
caller's caller.

alembic/command.py
alembic/ddl/impl.py
alembic/runtime/migration.py
alembic/util/messaging.py

index f8c81cc15105fb6e1c013182da7b971742ea7cbe..3faafddfb337ca826249d6bc4b2144d38f5f547c 100644 (file)
@@ -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:
index 5df7c040d0123acfb9554835f722336c4906143c..0843ebf1d73d62f5a8680214365516b7d23f372d 100644 (file)
@@ -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(
index a4ad74085514cd2baf6d0d5d4291c5e36fc5ae40..b3a98633271531541862d245c6e419edd7bf2018 100644 (file)
@@ -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:
index 1e72c195ccb14604e031c220b1429a47431b07fe..32c0c7e56def3bd1be8e3fab45659f821d1813e7 100644 (file)
@@ -69,8 +69,9 @@ def obfuscate_url_pw(u):
     return str(u)
 
 
-def warn(msg):
-    warnings.warn(msg)
+def warn(msg, stacklevel=2):
+    # Dy default report the warning from our caller's file/line-no, not here
+    warnings.warn(msg, stacklevel=stacklevel)
 
 
 def msg(msg, newline=True):