Skip to content

Commit 920c1ff

Browse files
knethclaude
andauthored
Merge SA 2.1 compat into core20.py, supporting both SA 2.0 and 2.1 (#254)
* Merge SA 2.1 compat into core20.py, supporting both SA 2.0 and 2.1 Consolidate `core21.py` into `core20.py` by guarding the three SA 2.1-specific differences behind `SA_VERSION >= SA_2_1` checks: - `visiting_cte` parameter and `toplevel` logic in `visit_update` - `update_post_criteria_clause` (renamed from `update_limit_clause`) - removal of the `_ordered_values` branch in `_get_crud_params` Delete `core21.py` and simplify the dialect dispatch to always use `CrateCompilerSA20` for SA >= 2.0. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Make linter happy --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent aa3376c commit 920c1ff

3 files changed

Lines changed: 26 additions & 437 deletions

File tree

src/sqlalchemy_cratedb/compat/core20.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,31 @@
4646
from sqlalchemy.sql.dml import isinsert as _compile_state_isinsert
4747

4848
from sqlalchemy_cratedb.compiler import CrateCompiler
49+
from sqlalchemy_cratedb.sa_version import SA_2_1, SA_VERSION
4950

5051

5152
class CrateCompilerSA20(CrateCompiler):
52-
def visit_update(self, update_stmt, **kw):
53+
def visit_update(self, update_stmt, visiting_cte=None, **kw):
5354
compile_state = update_stmt._compile_state_factory(update_stmt, self, **kw)
5455
update_stmt = compile_state.statement
5556

56-
# [20] CrateDB patch.
57+
# CrateDB patch.
5758
if not compile_state._dict_parameters and not hasattr(update_stmt, "_crate_specific"):
58-
return super().visit_update(update_stmt, **kw)
59+
if SA_VERSION >= SA_2_1:
60+
return super().visit_update(update_stmt, visiting_cte=visiting_cte, **kw)
61+
else:
62+
return super().visit_update(update_stmt, **kw)
63+
64+
# SA 2.1 introduced visiting_cte for CTE support.
65+
if SA_VERSION >= SA_2_1:
66+
if visiting_cte is not None:
67+
kw["visiting_cte"] = visiting_cte
68+
toplevel = False
69+
else:
70+
toplevel = not self.stack
71+
else:
72+
toplevel = not self.stack
5973

60-
toplevel = not self.stack
6174
if toplevel:
6275
self.isupdate = True
6376
if not self.dml_compile_state:
@@ -152,7 +165,11 @@ def visit_update(self, update_stmt, **kw):
152165
if t:
153166
text += " WHERE " + t
154167

155-
limit_clause = self.update_limit_clause(update_stmt)
168+
# SA 2.1 renamed update_limit_clause to update_post_criteria_clause.
169+
if SA_VERSION >= SA_2_1:
170+
limit_clause = self.update_post_criteria_clause(update_stmt, **kw)
171+
else:
172+
limit_clause = self.update_limit_clause(update_stmt)
156173
if limit_clause:
157174
text += " " + limit_clause
158175

@@ -275,7 +292,8 @@ def _get_crud_params(
275292
assert mp is not None
276293
spd = mp[0]
277294
stmt_parameter_tuples = list(spd.items())
278-
elif compile_state._ordered_values:
295+
elif SA_VERSION < SA_2_1 and compile_state._ordered_values:
296+
# _ordered_values was removed in SA 2.1.
279297
spd = compile_state._dict_parameters
280298
stmt_parameter_tuples = compile_state._ordered_values
281299
elif compile_state._dict_parameters:

0 commit comments

Comments
 (0)