From d2312512ed7e89c43728d4bab3ff1cc2bc867519 Mon Sep 17 00:00:00 2001 From: RamonWill Date: Thu, 9 Jul 2020 14:21:50 +0100 Subject: [PATCH] new test case for #4670. closes #4670 --- test/orm/test_query.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/orm/test_query.py b/test/orm/test_query.py index 7ef2a455ea..5beb75c1a4 100644 --- a/test/orm/test_query.py +++ b/test/orm/test_query.py @@ -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 -- 2.47.3