]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
restore generative to with_statement_hint
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 7 Aug 2024 16:18:25 +0000 (12:18 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 7 Aug 2024 16:19:05 +0000 (12:19 -0400)
Fixed regression in :meth:`_sql.Select.with_statement_hint` and others
where the generative behavior of the method stopped producing a copy of the
object.

Fixes: #11703
Change-Id: Ia4482f91f76fae9982dc6b075bf5cfec7042ffa6

doc/build/changelog/unreleased_20/11703.rst [new file with mode: 0644]
lib/sqlalchemy/sql/selectable.py
test/sql/test_select.py

diff --git a/doc/build/changelog/unreleased_20/11703.rst b/doc/build/changelog/unreleased_20/11703.rst
new file mode 100644 (file)
index 0000000..5c70313
--- /dev/null
@@ -0,0 +1,7 @@
+.. change::
+    :tags: bug, sql, regression
+    :tickets: 11703
+
+    Fixed regression in :meth:`_sql.Select.with_statement_hint` and others
+    where the generative behavior of the method stopped producing a copy of the
+    object.
index 3c9ca808a3e1f74c10a8af04493443ac22b7f49b..ad12b00342868c42dcbbfc293684319f5a893e54 100644 (file)
@@ -478,6 +478,7 @@ class HasHints:
         ("_hints", InternalTraversal.dp_table_hint_list),
     ]
 
+    @_generative
     def with_statement_hint(self, text: str, dialect_name: str = "*") -> Self:
         """Add a statement hint to this :class:`_expression.Select` or
         other selectable object.
index e772c5911d0f5653806694290341db56aac23bd8..2bef71dd1e5f5dabaa7c132f4443c1737063a529 100644 (file)
@@ -469,6 +469,21 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL):
             " %(joiner)s SELECT :param_3 AS anon_3" % {"joiner": joiner},
         )
 
+    @testing.combinations(
+        lambda stmt: stmt.with_statement_hint("some hint"),
+        lambda stmt: stmt.with_hint(table("x"), "some hint"),
+        lambda stmt: stmt.where(column("q") == 5),
+        lambda stmt: stmt.having(column("q") == 5),
+        lambda stmt: stmt.order_by(column("q")),
+        lambda stmt: stmt.group_by(column("q")),
+        # TODO: continue
+    )
+    def test_methods_generative(self, testcase):
+        s1 = select(1)
+        s2 = testing.resolve_lambda(testcase, stmt=s1)
+
+        assert s1 is not s2
+
 
 class ColumnCollectionAsSelectTest(fixtures.TestBase, AssertsCompiledSQL):
     """tests related to #8285."""