Skip to content

Commit 7844813

Browse files
authored
fix: POSTCOMPILE expansion in SQLAlchemy 1.4.27+ (#408)
* fix: POSTCOMPILE expansion in SQLAlchemy 1.4.27+ Handle the new double underscore prefix for POSTCOMPILE variables introduced in this version. * build: Widen sqlalchemy version support to include 1.4.27 * fix: IN expansion compliance test * fix(coverage): skip expansion coverage checks
1 parent e2f9821 commit 7844813

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def readme():
9090
# https://github.com/googleapis/python-bigquery-sqlalchemy/issues/386
9191
# and
9292
# https://github.com/googleapis/python-bigquery-sqlalchemy/issues/385
93-
"sqlalchemy>=1.2.0,<=1.4.26",
93+
"sqlalchemy>=1.2.0,<=1.4.27",
9494
"future",
9595
],
9696
extras_require=extras,

sqlalchemy_bigquery/base.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -341,16 +341,19 @@ def group_by_clause(self, select, **kw):
341341

342342
__sqlalchemy_version_info = tuple(map(int, sqlalchemy.__version__.split(".")))
343343

344-
__expandng_text = (
344+
__expanding_text = (
345345
"EXPANDING" if __sqlalchemy_version_info < (1, 4) else "POSTCOMPILE"
346346
)
347347

348+
# https://github.com/sqlalchemy/sqlalchemy/commit/f79df12bd6d99b8f6f09d4bf07722638c4b4c159
349+
__expanding_conflict = "" if __sqlalchemy_version_info < (1, 4, 27) else "__"
350+
348351
__in_expanding_bind = _helpers.substitute_string_re_method(
349352
fr"""
350353
\sIN\s\( # ' IN ('
351354
(
352-
\[ # Expanding placeholder
353-
{__expandng_text} # e.g. [EXPANDING_foo_1]
355+
{__expanding_conflict}\[ # Expanding placeholder
356+
{__expanding_text} # e.g. [EXPANDING_foo_1]
354357
_[^\]]+ #
355358
\]
356359
(:[A-Z0-9]+)? # type marker (e.g. ':INT64'
@@ -431,7 +434,9 @@ def visit_notendswith_op_binary(self, binary, operator, **kw):
431434

432435
__placeholder = re.compile(r"%\(([^\]:]+)(:[^\]:]+)?\)s$").match
433436

434-
__expanded_param = re.compile(fr"\(\[" fr"{__expandng_text}" fr"_[^\]]+\]\)$").match
437+
__expanded_param = re.compile(
438+
fr"\({__expanding_conflict}\[" fr"{__expanding_text}" fr"_[^\]]+\]\)$"
439+
).match
435440

436441
__remove_type_parameter = _helpers.substitute_string_re_method(
437442
r"""
@@ -521,9 +526,10 @@ def visit_bindparam(
521526

522527
assert_(param != "%s", f"Unexpected param: {param}")
523528

524-
if bindparam.expanding:
529+
if bindparam.expanding: # pragma: NO COVER
525530
assert_(self.__expanded_param(param), f"Unexpected param: {param}")
526-
param = param.replace(")", f":{bq_type})")
531+
if self.__sqlalchemy_version_info < (1, 4, 27):
532+
param = param.replace(")", f":{bq_type})")
527533

528534
else:
529535
m = self.__placeholder(param)

0 commit comments

Comments
 (0)