]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
remove use of SQL expressions in "modifiers" for regexp
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 30 Jun 2023 14:14:55 +0000 (10:14 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 3 Jul 2023 12:38:26 +0000 (08:38 -0400)
commite9681237daa186b0d3d49e365c0859c5ac844d2b
tree5444c69b9993a8130c3dafad49e27ffd9eb12829
parent0afb399b4e312a6639f2da0d5f552197b158798d
remove use of SQL expressions in "modifiers" for regexp

Fixed issue where the :meth:`_sql.ColumnOperators.regexp_match`
when using "flags" would not produce a "stable" cache key, that
is, the cache key would keep changing each time causing cache pollution.
The same issue existed for :meth:`_sql.ColumnOperators.regexp_replace`
with both the flags and the actual replacement expression.
The flags are now represented as fixed modifier strings rendered as
safestrings rather than bound parameters, and the replacement
expression is established within the primary portion of the "binary"
element so that it generates an appropriate cache key.

Note that as part of this change, the
:paramref:`_sql.ColumnOperators.regexp_match.flags` and
:paramref:`_sql.ColumnOperators.regexp_replace.flags` have been modified to
render as literal strings only, whereas previously they were rendered as
full SQL expressions, typically bound parameters.   These parameters should
always be passed as plain Python strings and not as SQL expression
constructs; it's not expected that SQL expression constructs were used in
practice for this parameter, so this is a backwards-incompatible change.

The change also modifies the internal structure of the expression
generated, for :meth:`_sql.ColumnOperators.regexp_replace` with or without
flags, and for :meth:`_sql.ColumnOperators.regexp_match` with flags. Third
party dialects which may have implemented regexp implementations of their
own (no such dialects could be located in a search, so impact is expected
to be low) would need to adjust the traversal of the structure to
accommodate.

Fixed issue in mostly-internal :class:`.CacheKey` construct where the
``__ne__()`` operator were not properly implemented, leading to nonsensical
results when comparing :class:`.CacheKey` instances to each other.

Fixes: #10042
Change-Id: I2e245f81d7ee7136ad04cf77be35f9745c5da5e5
(cherry picked from commit 2d8ff4f9171bcef9fa70dfa27f2c0cab708fd75e)
13 files changed:
doc/build/changelog/unreleased_14/10042.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/mysql/base.py
lib/sqlalchemy/dialects/oracle/base.py
lib/sqlalchemy/dialects/postgresql/base.py
lib/sqlalchemy/sql/compiler.py
lib/sqlalchemy/sql/default_comparator.py
lib/sqlalchemy/sql/operators.py
lib/sqlalchemy/sql/traversals.py
test/dialect/mysql/test_compiler.py
test/dialect/oracle/test_compiler.py
test/dialect/postgresql/test_compiler.py
test/sql/test_compare.py
test/sql/test_operators.py