From: Valery Yundin Date: Fri, 16 Dec 2016 14:22:08 +0000 (-0500) Subject: Better hide engine password X-Git-Tag: rel_1_1_5~9^2^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bccc1419a67c06636b5d5a8d5c00612b7d843edd;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Better hide engine password 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 --- diff --git a/doc/build/changelog/changelog_11.rst b/doc/build/changelog/changelog_11.rst index 484945ebd4..d071d48c50 100644 --- a/doc/build/changelog/changelog_11.rst +++ b/doc/build/changelog/changelog_11.rst @@ -119,6 +119,15 @@ 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 diff --git a/lib/sqlalchemy/engine/threadlocal.py b/lib/sqlalchemy/engine/threadlocal.py index a22b59c1de..ee31764f39 100644 --- a/lib/sqlalchemy/engine/threadlocal.py +++ b/lib/sqlalchemy/engine/threadlocal.py @@ -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 diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py index 793750f1c0..9bb0eee43f 100644 --- a/lib/sqlalchemy/sql/schema.py +++ b/lib/sqlalchemy/sql/schema.py @@ -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] diff --git a/test/engine/test_reflection.py b/test/engine/test_reflection.py index 869fd63e57..0bc5b111e1 100644 --- a/test/engine/test_reflection.py +++ b/test/engine/test_reflection.py @@ -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=[])