]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Better hide engine password
authorValery Yundin <yuvalery@gmail.com>
Fri, 16 Dec 2016 14:22:08 +0000 (09:22 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 16 Jan 2017 19:02:26 +0000 (14:02 -0500)
Avoid putting engine password in the exception message in
`MetaData.reflect` (since exception messages often appear in logs).
Use the same redacted `__repr__` implementation in
`TLEngine` as in its base class `Engine`

Change-Id: Ic0a7baea917a9c8d87dffdd82ef566673ab08e02
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/327

doc/build/changelog/changelog_11.rst
lib/sqlalchemy/engine/threadlocal.py
lib/sqlalchemy/sql/schema.py
test/engine/test_reflection.py

index 484945ebd4dc1ec36f3a1769a390f89911041b37..d071d48c50505fff9352645689fc92c3ab0f7d9b 100644 (file)
         be inserted into the query in the case that the :class:`.Bundle`
         construct were used as the selection criteria.
 
+    .. change:: repr_for_url_reflect
+        :tags: bug, sql
+
+        The engine URL embedded in the exception for "could not reflect"
+        in :meth:`.MetaData.reflect` now conceals the password; also
+        the ``__repr__`` for :class:`.TLEngine` now acts like that of
+        :class:`.Engine`, concealing the URL password.  Pull request courtesy
+        Valery Yundin.
+
     .. change:: pg_timestamp_zero_prec
         :tags: bug, postgresql
 
index a22b59c1debcb54db3a1908778d27f112787c0bf..ee31764f39e48f61da085ab5fe2bce0e5cbdbd98 100644 (file)
@@ -135,4 +135,4 @@ class TLEngine(base.Engine):
             self._connections.trans = []
 
     def __repr__(self):
-        return 'TLEngine(%s)' % str(self.url)
+        return 'TLEngine(%r)' % self.url
index 793750f1c0ef44a2cf1b85ba97f4f16f7f944712..9bb0eee43f9948a5f7ad8c9ff40b9b4ec66a820b 100644 (file)
@@ -3811,8 +3811,8 @@ class MetaData(SchemaItem):
                     s = schema and (" schema '%s'" % schema) or ''
                     raise exc.InvalidRequestError(
                         'Could not reflect: requested table(s) not available '
-                        'in %s%s: (%s)' %
-                        (bind.engine.url, s, ', '.join(missing)))
+                        'in %r%s: (%s)' %
+                        (bind.engine, s, ', '.join(missing)))
                 load = [name for name in only if extend_existing or
                         name not in current]
 
index 869fd63e57ff283ac44ffe75b023e06aa203ee79..0bc5b111e1ace3122e9c789820fd0e5a81853479 100644 (file)
@@ -932,11 +932,13 @@ class ReflectionTest(fixtures.TestBase, ComparesTables):
         self.assert_(set(m3.tables.keys()) == set(['rt_c']))
 
         m4 = MetaData(testing.db)
-        try:
-            m4.reflect(only=['rt_a', 'rt_f'])
-            self.assert_(False)
-        except sa.exc.InvalidRequestError as e:
-            self.assert_(e.args[0].endswith('(rt_f)'))
+
+        assert_raises_message(
+            sa.exc.InvalidRequestError,
+            r"Could not reflect: requested table\(s\) not available in "
+            r"Engine\(.*?\): \(rt_f\)",
+            m4.reflect, only=['rt_a', 'rt_f']
+        )
 
         m5 = MetaData(testing.db)
         m5.reflect(only=[])