--- /dev/null
+.. change::
+ :tags: bug, orm
+ :tickets: 9526
+
+ Fixed issue where the :meth:`_sql.BindParameter.render_literal_execute`
+ method would fail when called on a parameter that also had ORM annotations
+ associated with it. In practice, this would be observed as a failure of SQL
+ compilation when using some combinations of a dialect that uses "FETCH
+ FIRST" such as Oracle along with a :class:`_sql.Select` construct that uses
+ :meth:`_sql.Select.limit`, within some ORM contexts, including if the
+ statement were embedded within a relationship primaryjoin expression.
+
default_schema_name=None,
from_linting=False,
check_param_order=True,
+ use_literal_execute_for_simple_int=False,
):
if use_default_dialect:
dialect = default.DefaultDialect()
if render_postcompile:
compile_kwargs["render_postcompile"] = True
+ if use_literal_execute_for_simple_int:
+ compile_kwargs["use_literal_execute_for_simple_int"] = True
+
if for_executemany:
kw["for_executemany"] = True
from sqlalchemy.sql import visitors
from sqlalchemy.sql.elements import _clone
from sqlalchemy.sql.expression import _from_objects
+from sqlalchemy.sql.util import _deep_annotate
from sqlalchemy.sql.visitors import ClauseVisitor
from sqlalchemy.sql.visitors import cloned_traverse
from sqlalchemy.sql.visitors import CloningVisitor
self.assert_compile(adapted, expected)
+ @testing.variation("annotate", [True, False])
+ def test_bindparam_render_literal_execute(self, annotate):
+ """test #9526"""
+
+ bp = bindparam("some_value")
+
+ if annotate:
+ bp = bp._annotate({"foo": "bar"})
+
+ bp = bp.render_literal_execute()
+ self.assert_compile(
+ column("q") == bp, "q = __[POSTCOMPILE_some_value]"
+ )
+
+ @testing.variation("limit_type", ["limit", "fetch"])
+ @testing.variation("dialect", ["default", "oracle"])
+ def test_annotated_fetch(self, limit_type: testing.Variation, dialect):
+ """test #9526"""
+
+ if limit_type.limit:
+ stmt = select(column("q")).limit(1)
+ elif limit_type.fetch:
+ stmt = select(column("q")).fetch(1)
+ else:
+ limit_type.fail()
+
+ stmt = _deep_annotate(stmt, {"foo": "bar"})
+
+ if limit_type.limit:
+ if dialect.default:
+ self.assert_compile(
+ stmt,
+ "SELECT q LIMIT :param_1",
+ use_literal_execute_for_simple_int=True,
+ dialect=dialect.name,
+ )
+ elif dialect.oracle:
+ self.assert_compile(
+ stmt,
+ "SELECT q FROM DUAL FETCH FIRST "
+ "__[POSTCOMPILE_param_1] ROWS ONLY",
+ dialect=dialect.name,
+ )
+ else:
+ dialect.fail()
+ elif limit_type.fetch:
+ if dialect.default:
+ self.assert_compile(
+ stmt,
+ "SELECT q FETCH FIRST __[POSTCOMPILE_param_1] ROWS ONLY",
+ use_literal_execute_for_simple_int=True,
+ dialect=dialect.name,
+ )
+ elif dialect.oracle:
+ self.assert_compile(
+ stmt,
+ "SELECT q FROM DUAL FETCH FIRST "
+ "__[POSTCOMPILE_param_1] ROWS ONLY",
+ dialect=dialect.name,
+ )
+ else:
+ dialect.fail()
+ else:
+ limit_type.fail()
+
@testing.combinations((null(),), (true(),))
def test_dont_adapt_singleton_elements(self, elem):
"""test :ticket:`6259`"""