Skip to content

Commit a72fa39

Browse files
authored
SNOW-857216: fix compatibility issue with sqlalchemy 1.4.49 (snowflakedb#423)
1 parent c200f97 commit a72fa39

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

Diff for: DESCRIPTION.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ Source code is also available at:
1111

1212
- v1.4.8(TBD)
1313

14-
- Added opiton to create a temporary stage command.
14+
- Added option to create a temporary stage command.
15+
- Fixed a compatibility issue of regex expression with SQLAlchemy 1.4.49.
1516

1617
- v1.4.7(Mar 22, 2023)
1718

Diff for: src/snowflake/sqlalchemy/base.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,14 @@ def visit_regexp_match_op_binary(self, binary, operator, **kw):
376376

377377
def visit_regexp_replace_op_binary(self, binary, operator, **kw):
378378
string, pattern, flags = self._get_regexp_args(binary, kw)
379-
replacement = self.process(binary.modifiers["replacement"], **kw)
379+
try:
380+
replacement = self.process(binary.modifiers["replacement"], **kw)
381+
except KeyError:
382+
# in sqlalchemy 1.4.49, the internal structure of the expression is changed
383+
# that binary.modifiers doesn't have "replacement":
384+
# https://docs.sqlalchemy.org/en/20/changelog/changelog_14.html#change-1.4.49
385+
return f"REGEXP_REPLACE({string}, {pattern}{'' if flags is None else f', {flags}'})"
386+
380387
if flags is None:
381388
return f"REGEXP_REPLACE({string}, {pattern}, {replacement})"
382389
else:

Diff for: tests/connector_regression

0 commit comments

Comments
 (0)