]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
new test case for #4670. closes #4670
authorRamonWill <ramonwilliams@hotmail.co.uk>
Thu, 9 Jul 2020 13:21:50 +0000 (14:21 +0100)
committerRamonWill <ramonwilliams@hotmail.co.uk>
Thu, 9 Jul 2020 13:21:50 +0000 (14:21 +0100)
test/orm/test_query.py

index 7ef2a455ea55830a7278381f40f750e9ef032d35..5beb75c1a48174aa43b5587afbed9bedc59a8f47 100644 (file)
@@ -12,6 +12,7 @@ from sqlalchemy import collate
 from sqlalchemy import column
 from sqlalchemy import desc
 from sqlalchemy import distinct
+from sqlalchemy import event
 from sqlalchemy import exc as sa_exc
 from sqlalchemy import exists
 from sqlalchemy import ForeignKey
@@ -5820,6 +5821,23 @@ class ExecutionOptionsTest(QueryTest):
         q1 = sess.query(User).execution_options(**execution_options)
         q1.all()
 
+    def test_options_before_compile(self):
+        @event.listens_for(Query, "before_compile", retval=True)
+        def _before_compile(query):
+            return query.execution_options(my_option=True)
+
+        opts = {}
+
+        @event.listens_for(testing.db, "before_cursor_execute")
+        def _before_cursor_execute(
+            conn, cursor, statement, parameters, context, executemany
+        ):
+            opts.update(context.execution_options)
+
+        sess = create_session(bind=testing.db, autocommit=False)
+        sess.query(column("1")).all()
+        eq_(opts["my_option"], True)
+
 
 class BooleanEvalTest(fixtures.TestBase, testing.AssertsCompiledSQL):
     """test standalone booleans being wrapped in an AsBoolean, as well