Skip to content

Commit 1ba30c8

Browse files
committed
fix: strip RETURNING from translated optimized_sql, not from original_sql plan
_prepare_sql step 5: plan.stripped_sql was built from original_sql (untranslated), so using it to overwrite optimized_sql discarded the entire normalization pipeline. optimized_sql still had DEFAULT, $1 params, unquoted schema names etc. → SQLCODE -12. Fix: when original_sql is provided, call ReturningPlan._strip_clauses() on optimized_sql directly using plan.returning_clause and plan.on_conflict_clause (metadata from original_sql, stripping applied to translated form). Bumps version to 1.5.7.
1 parent 2786891 commit 1ba30c8

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [1.5.7] - 2026-03-09
11+
12+
### Fixed
13+
- **`_prepare_sql` overwrote translated SQL with untranslated original after RETURNING strip**: After the 1.5.6 fix, `_prepare_sql` correctly used `original_sql` for `ReturningPlan.from_sql` RETURNING detection. However, line 699 then unconditionally did `optimized_sql = plan.stripped_sql`. Since `plan` was built from `original_sql`, `plan.stripped_sql` was the *original* (untranslated) SQL with just `RETURNING` removed — still containing `DEFAULT`, `$1`-style params, unquoted schema names, etc. This overwrote the correctly-translated `optimized_sql` from the normalization pipeline, causing IRIS to receive e.g. `INSERT INTO "SESSION" (...) VALUES (..., DEFAULT)``SQLCODE -12`. Fixed by applying `ReturningPlan._strip_clauses()` directly to `optimized_sql` when `original_sql` was provided, rather than using `plan.stripped_sql`. The `else` branch (no `original_sql`) continues to use `plan.stripped_sql` as before.
14+
1015
## [1.5.6] - 2026-03-09
1116

1217
### Fixed

src/iris_pgwire/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
caretdev/sqlalchemy-iris.
77
"""
88

9-
__version__ = "1.5.6"
9+
__version__ = "1.5.7"
1010
__author__ = "Thomas Dyar <thomas.dyar@intersystems.com>"
1111

1212
# Don't import server/protocol in __init__ to avoid sys.modules conflicts

src/iris_pgwire/iris_executor.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,18 @@ def _prepare_sql(
696696
columns=plan.columns,
697697
session_id=session_id,
698698
)
699-
optimized_sql = plan.stripped_sql
699+
# Strip RETURNING / ON CONFLICT from the *translated* optimized_sql.
700+
# When original_sql was provided, plan.stripped_sql is the original (untranslated)
701+
# SQL with only RETURNING removed — we must NOT use it to overwrite optimized_sql or
702+
# we'd undo the entire normalization pipeline (DEFAULT, $1 params, schema names, etc.
703+
# still present → IRIS SQLCODE -12).
704+
# Instead, apply the same stripping regex directly to optimized_sql.
705+
if original_sql:
706+
optimized_sql = ReturningPlan._strip_clauses(
707+
optimized_sql, plan.returning_clause, plan.on_conflict_clause
708+
)
709+
else:
710+
optimized_sql = plan.stripped_sql
700711

701712
# 6. Semicolon Stripping
702713
optimized_sql = optimized_sql.strip().rstrip(";")

0 commit comments

Comments
 (0)