From: RamonWill Date: Thu, 13 Aug 2020 21:04:13 +0000 (-0400) Subject: Test execution_options on Query object before compilation X-Git-Tag: rel_1_4_0b1~171^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0d874b36664d2f817edaa009358d5d2455711fdc;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Test execution_options on Query object before compilation A test that checks if the execution options are being set on the Query object before compilation ### Description Since Issue #4670 has been open there have changes to the execution mechanics that resolved it. I have just created a test case that will enable the issue to be closed. This pull request is: - [ X] A documentation / typographical error fix - Good to go, no issue or tests are needed - [ ] A short code fix - please include the issue number, and create an issue if none exists, which must include a complete example of the issue. one line code fixes without an issue and demonstration will not be accepted. - Please include: `Fixes: #` in the commit message - please include tests. one line code fixes without tests will not be accepted. - [ ] A new feature implementation - please include the issue number, and create an issue if none exists, which must include a complete example of how the feature would look. - Please include: `Fixes: #` in the commit message - please include tests. **Have a nice day!** Fixes: #4670 Closes: #5446 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5446 Pull-request-sha: c98639ec94279760caacf9f288b180198511dfd3 Change-Id: I686dc7a4735000748c94bff5ba6dc7bd57b2d1c4 --- diff --git a/test/orm/test_events.py b/test/orm/test_events.py index df48cfe63c..aff47d96ef 100644 --- a/test/orm/test_events.py +++ b/test/orm/test_events.py @@ -2768,6 +2768,25 @@ class QueryEventsTest( ) ) + def test_before_compile_execution_options(self): + User = self.classes.User + + @event.listens_for(query.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(User).first() + eq_(opts["my_option"], True) + class RefreshFlushInReturningTest(fixtures.MappedTest): """test [ticket:3427].