]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Strip special chars in anonymized bind names
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 4 Sep 2019 22:46:53 +0000 (18:46 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 5 Sep 2019 13:53:37 +0000 (09:53 -0400)
commitd7aa017d83b416187b54ad38400475fd86d80671
tree61e864530882f36733c12dadcb135af5a9d7d676
parentc3dcdbd21de44b23e527f5580c318e47ea6930a7
Strip special chars in anonymized bind names

Characters that interfere with "pyformat" or "named" formats in bound
parameters, namely ``%, (, )`` and the space character, as well as a few
other typically undesirable characters, are stripped early for a
:func:`.bindparam` that is using an anonymized name, which is typically
generated automatically from a named column which itself includes these
characters in its name and does not use a ``.key``, so that they do not
interfere either with the SQLAlchemy compiler's use of string formatting or
with the driver-level parsing of the parameter, both of which could be
demonstrated before the fix.  The change only applies to anonymized
parameter names that are generated and consumed internally, not end-user
defined names, so the change should have no impact on any existing code.
Applies in particular to the psycopg2 driver which does not otherwise quote
special parameter names, but also strips leading underscores to suit Oracle
(but not yet leading numbers, as some anon parameters are currently
entirely numeric/underscore based); Oracle in any case continues to quote
parameter names that include special characters.

Fixes: #4837
Change-Id: I21cb654c3e4ef786114160b8b4295242720bf3f9
doc/build/changelog/unreleased_13/4837.rst [new file with mode: 0644]
lib/sqlalchemy/sql/elements.py
test/dialect/oracle/test_compiler.py
test/sql/test_compiler.py